2017-07-10 35 views
0

問題:使用SystemJS與噶 - 404上的package.json

試圖SystemJS配置與使用噶整合karma-systemjs然而噶抱怨不能夠找到每個進口的package.json文件:

... 
10 07 2017 13:38:15.107:WARN [web-server]: 404: /node_modules/angular-mocks/package.json 
10 07 2017 13:38:15.380:WARN [web-server]: 404: /node_modules/moment/package.json 
10 07 2017 13:38:15.382:WARN [web-server]: 404: /node_modules/angular/package.json 
PhantomJS 2.1.1 (Windows 7 0.0.0) ERROR 
    Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:9876/node_modules/angular-mocks/package.json 
    Error loading http://localhost:9876/node_modules/angular-mocks/package.json 
    Error loading build/js/app.spec.js 

PhantomJS 2.1.1 (Windows 7 0.0.0): Executed 0 of 0 ERROR (0.945 secs/0 secs) 

上面已被截斷,但輸出上方還有幾處丟失的package.json警告。此外這些錯誤只與Karma有關,實際上應用程序本身在下面的設置下運行良好。

相關版本:

  • "karma": "1.7.0"
  • "karma-jasmine": "1.1.0"
  • "karma-systemjs": "0.16.0"
  • "systemjs": "0.19.47"

SystemJS配置:

(從引用:https://github.com/systemjs/systemjs/issues/767#issuecomment-139515090

System.config({ 
    defaultJSExtensions: true, 
    transpiler: "babel", 
    babelOptions: { 
    "optional": [ 
     "runtime", 
     "optimisation.modules.system" 
    ] 
    }, 
    paths: { 
    '*': './node_modules/*', 
    }, 
    packageConfigPaths: ['./node_modules/*/package.json'], 
    map: { 
    'systemjs': './node_modules/systemjs/dist/system.js', 
    'system-polyfills': './node_modules/systemjs/dist/system-polyfills.js', 
    'babel': './node_modules/babel-core/browser.js', 
    'angular-feature-flags': './node_modules/angular-feature-flags/dist/featureFlags.min.js', 
    crypto: '@empty', 
    fs: '@empty', 
    stream: '@empty' 
    } 
}); 

噶配置:

module.exports = function (config) { 
    "use strict"; 
    config.set({ 
    autoWatch: true, 
    singleRun: false, 
    port: 9876, 
    frameworks: ["systemjs", "jasmine"], 

    babelPreprocessor: { 
     options: { 
     compact: true 
     } 
    }, 

    files: [ 
     "node_modules/phantomjs-polyfill-object-assign/object-assign-polyfill.js", 
     {pattern: "app/assets/images/**/*", watched: false, included: false, served: true}, 
     "build/**/*spec*.js" 
    ], 

    systemjs: { 
     configFile: "./config.js", 
     serveFiles: [ 
     './build/**/*.js' 
     ] 
    }, 
    browsers: ["PhantomJS"], 
    reporters: ["spec"] 
    }); 

}; 

回答

0

karma-systemjs應該讀你SystemJS配置和自動告訴karma服務,你告訴SystemJS文件關於。然而,我看了karma-systemjs的代碼,我沒有看到任何條款來處理packageConfigPaths。 (而該項目needs a new maintainer,不鼓舞信心)因此,你應該將元素添加到喜歡你files配置:

{ pattern: "node_modules/**/package.json", included: false } 

我建議用**,這樣就可以自動處理像node_modules/@angular/core/package.json路徑模式,這是一個以上的深度。

+0

嘗試了您的建議,但問題仍然存在,錯誤輸出沒有任何更改。 – patryk0605