【问题标题】:Karma + Webpack + Babel. Can't get Babel to transpile source or test files业力 + Webpack + Babel。无法让 Babel 转译源文件或测试文件
【发布时间】:2017-06-09 19:01:58
【问题描述】:

尝试运行用 ES6 编写的最简单的 jasmine 测试:

单元/page.test.js

describe("test", function () {
    it("test", function () {
        [].find();
        // Object.assign(); // this fails as well
    });
});

我收到以下错误:

TypeError: undefined is not a constructor (evaluating 'Object.assign()') in page.test.js (line 145)

看起来它不知道新的 ES6 方法。我觉得 polyfill 是缺失的部分。

package.json

{
  "name": "tests",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "test": "karma start"
  },
  "author": "eagor",
  "devDependencies": {
    "babel-core": "^6.21.0",
    "babel-loader": "^6.2.10",
    "babel-preset-latest": "^6.16.0",
    "jasmine": "^2.5.3",
    "jasmine-core": "^2.5.2",
    "karma": "^1.4.0",
    "karma-babel-polyfill": "0.0.5",
    "karma-babel-preprocessor": "^6.0.1",
    "karma-jasmine": "^1.1.0",
    "karma-phantomjs-launcher": "^1.0.2",
    "karma-webpack": "^2.0.1",
    "webpack": "^1.14.0"
  }
}

karma.conf.js

module.exports = function(config) {
    config.set({
        browsers: ['PhantomJS'],
        basePath: "./Unit",
        files: [
            { pattern: '**/*.test.js', watched: false }
        ],
        frameworks: ['jasmine'],
        preprocessors: {
            '**/*.test.js': ['webpack']
        },
        webpack: {
            module: {
                loaders: [
                    { test: /\.js/, exclude: /node_modules/, loader: 'babel-loader' }
                ]
            },
            // watch: true
        },
        webpackServer: {
            noInfo: true
        }
    });
};

【问题讨论】:

    标签: webpack karma-runner babeljs webpack-2


    【解决方案1】:

    我在这里遇到了同样的问题。我试图在 Webpack 的 repo but it got shut down with no further notice 上打开一个问题。我设法通过添加.babelrc 解决了这个问题,它昨天工作了。今晚,我一点也不碰这个项目,我的测试不再起作用了。 Karma 和 Webpack 之间可能有问题。

    【讨论】:

      猜你喜欢
      • 2018-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-14
      • 2019-08-15
      • 1970-01-01
      • 2017-09-24
      • 2019-12-18
      相关资源
      最近更新 更多