简体   繁体   English

Angular 2 - Karma 错误 - 模块解析失败“您可能需要合适的加载程序来处理此文件类型”

[英]Angular 2 - Karma Error - Module Parse Failed 'You may need an appropriate loader to handle this file type'

I am setting up Karma for my angular 2 Application.我正在为我的 angular 2 应用程序设置 Karma。 I am getting an error for missing plugin.. can you help please.我收到一个缺少插件的错误..你能帮忙吗? I am using https://github.com/AngularClass/angular2-webpack-starter for reference.我正在使用https://github.com/AngularClass/angular2-webpack-starter作为参考。 here is my dev-dependencies for karma.这是我对业力的开发依赖。

"istanbul": "^0.4.5",
    "jasmine-core": "^2.4.1",
    "json-loader": "^0.5.4",
    "karma": "^1.3.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-coverage": "^1.1.1",
    "karma-istanbul-reporter": "0.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-mocha-reporter": "^2.2.0",
    "karma-remap-coverage": "^0.1.2",
    "karma-sourcemap-loader": "^0.3.7",
    "karma-webpack": "^1.8.0",
    "lodash-webpack-plugin": "^0.10.2",
    "npm-scripts-info": "^0.3.6",
    "raw-loader": "0.5.1",
    "rimraf": "^2.5.2",
    "source-map": "^0.5.6",
    "source-map-loader": "^0.1.5",

here is my karma.conf.js这是我的 karma.conf.js

var webpackConfig = require('./webpack.test');

module.exports = function (config) {
  var _config = {
    basePath: '',

    frameworks: ['jasmine'],

    files: [
      {pattern: './config/karma-test-shim.js', watched: false}
    ],

    preprocessors: {
      './config/karma-test-shim.js': ['coverage','webpack', 'sourcemap'],
      './src/**/!(*.spec).(ts|js)': ['sourcemap']
    },

    webpack: webpackConfig,
    coverageReporter: {
      type: 'in-memory'
    },

    remapCoverageReporter: {
      'text-summary': null,
      json: './coverage/coverage.json',
      html: './coverage/html'
    },
    webpackMiddleware: {
      stats: 'errors-only'
    },

    webpackServer: {
      noInfo: true
    },

    //reporters: ['progress'],
     /*
     * test results reporter to use
     *
     * possible values: 'dots', 'progress'
     * available reporters: https://npmjs.org/browse/keyword/karma-reporter
     */
    reporters: [ 'mocha', 'coverage', 'remap-coverage' ],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: false,
    browsers: ['Chrome'],
    singleRun: true
  };

  config.set(_config);
};

I am getting this error on run:我在运行时收到此错误:

Chrome 54.0.2840 (Windows 7 0.0.0) ERROR
  Uncaught Error: Module parse failed: {location}\src\app\app.component.spec.ts Unexpected t
oken (13:57)
  You may need an appropriate loader to handle this file type.
  |     ]}));
  |
  |   it('should have a state', inject([ AppComponent ], (app: AppComponent) => {
  |     expect(app.state).toEqual('blank');
  |   }));

at config/karma-test-shim.js:69437在 config/karma-test-shim.js:69437

I think this is similar to question .我认为这类似于question

You need to add following change in your webpack.test.js (webpack config file):您需要在 webpack.test.js(webpack 配置文件)中添加以下更改:

try updating loader 'awesome-typescript-loader' like this:尝试像这样更新 loader 'awesome-typescript-loader':

{
   loader: 'awesome-typescript-loader?presets[]=es2017',
   options: { configFileName: helpers.root('src', 'tsconfig.json') }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的错误:模块解析失败:您可能需要合适的加载程序来处理此文件类型 - Uncaught Error: Module parse failed:You may need an appropriate loader to handle this file type Cypress 测试 - 在 typescript 中运行 cypress 测试时,Cucumber 功能文件给出错误“您可能需要适当的加载程序来处理此文件” - Cypress Test - Cucumber feature files giving error "You may need an appropriate loader to handle this file" while running cypress tests in typescript 失败:没有Reflector的提供者! 使用业力在angular2中运行测试时出错 - Failed: No provider for Reflector! error when running tests in angular2 with karma 无法使用Angular 1.4.9运行Karma并出现错误angular.module(…).info不是一个函数 - Can't run Karma with Angular 1.4.9 with error angular.module(…).info is not a function AngularJS + Karma + Ng-html2js =>无法实例化模块... html - AngularJS + Karma + Ng-html2js => Failed to instantiate module …html 开玩笑/反应/还原错误:动作可能没有未定义的“类型”属性。 你拼错了常量吗? 行动:{} - Jest/React/Redux error: Actions may not have an undefined “type” property. Have you misspelled a constant? Action: {} 失败:模板解析错误:Angular 2 - Failed: Template parse errors: Angular 2 许多失败:模板解析错误:无法绑定到“routerLink”,因为它不是“a”的已知属性。 Karma 中的错误 - Lots of Failed: Template parse errors: Can't bind to 'routerLink' since it isn't a known property of 'a'. errors in Karma 如何在Karma中运行特定的测试文件? (角度4+) - How to run a specific test file in Karma? (Angular 4+) 无法在_normalizeProvider中读取未定义的因果报应角度2错误 - Karma angular 2 error cannot read foreach of undefined at _normalizeProvider
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM