未捕获的ReferenceError:未定义require - 目标为es6

时间:2016-05-10 00:52:37

标签: build typescript phantomjs ecmascript-6 karma-jasmine

我正在使用Uncaught ReferenceError: require is not defined获得jasmine单元测试中的karma

这是我的karma.conf.js文件。

tsconfig.json - 目标"target": "es6"

module.exports = function (config) {
  config.set({
    basePath: './',
    frameworks: ['jasmine'],
    files: [
      'node_modules/reflect-metadata/Reflect.js',
      'node_modules/systemjs/dist/system-polyfills.js',
      'node_modules/systemjs/dist/system.src.js',
      { pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
      { pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false },
      { pattern: 'dist/dev/**/*.js', included: false, watched: true },
      { pattern: 'node_modules/systemjs/dist/system-polyfills.js', included: false, watched: false }, // PhantomJS2 (and possibly others) might require it
      'dist/**/*.spec.js',
    ],
    proxies: { },
    exclude: [    ],
    preprocessors: {
      'dist/**/!(*spec).js': ['coverage']
    },
    reporters: ['mocha', 'coverage'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: [
      'PhantomJS',
      'Chrome'
    ],
    singleRun: false,
    client: {    }
  });
};

enter image description here

1 个答案:

答案 0 :(得分:0)

建议使用额外--module commonjs编译代码并使用了解commonjs的karma插件,即https://github.com/karma-runner/karma-commonjs