javascript Karma 无法加载 webpack

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31444743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 13:48:13  来源:igfitidea点击:

Karma can't load webpack

javascriptkarma-runnerwebpackkarma-mocha

提问by Bulkan

I'm getting this error;

我收到此错误;

16 07 2015 13:03:52.741:WARN [preprocess]: Can not load "webpack"!
   Error: Can not resolve circular dependency! (Resolving: preprocessor:webpack -> webpackPlugin -> preprocessor:webpack)

My karma.conf looks like;

我的 karma.conf 看起来像;

var webpack = require('webpack');

module.exports = function (config) {
  config.set({
    browsers: [ 'Chrome' ], //run in Chrome
    singleRun: true, //just run once by default
    frameworks: [ 'mocha' ], //use the mocha test framework
    files: [
      'tests.webpack.js' //just load this file
    ],
    preprocessors: {
      'tests.webpack.js': [ 'webpack', 'sourcemap' ] //preprocess with webpack and our sourcemap loader
    },
    reporters: [ 'dots' ], //report results in this format
    webpack: { //kind of a copy of your webpack config
      devtool: 'inline-source-map', //just do inline source maps instead of the default
      module: {
        loaders: [
          { test: /\.js$/, loader: 'babel-loader' }
        ]
      }
    },
    webpackServer: {
      noInfo: true //please don't spam the console when running in karma!
    }
  });
};

and tests.webpack.js

和tests.webpack.js

var context = require.context('./src', true, /-test\.js$/); //make sure you have your directory and regex test set correctly!
context.keys().forEach(context);

I do have karma and karma-webpack installed.

我确实安装了 karma 和 karma-webpack。

Any ideas ?

有任何想法吗 ?

采纳答案by Oleg Isonen

Something has changed in the latest versions of karma-* projects. I have got the same issue as I installed everything latest. Now I tried exactly the versions hereand it worked out.

最新版本的 karma-* 项目发生了一些变化。我遇到了同样的问题,因为我安装了最新的所有东西。现在我完全尝试了这里的版本并且成功了。

回答by adu

I had a similar error but the post referenced in the accepted solution did not work for me. If you're looking for alternatives, read below!

我有一个类似的错误,但接受的解决方案中引用的帖子对我不起作用。如果您正在寻找替代品,请阅读以下内容!



I was seeing the following error message:

我看到以下错误消息:

WARN [preprocess]: Can not load "webpack"!
TypeError: Object [object Object] has no method 'refreshFiles'
at Plugin.notifyKarmaAboutChanges (/Users/abhandaru/workspace/source/macaw-campaigns/node_modules/karma-webpack/index.js:108:15)
at Plugin.<anonymous> (/Users/abhandaru/workspace/source/macaw-campaigns/node_modules/karma-webpack/index.js:72:9)
at Tapable.applyPlugins (/Users/abhandaru/workspace/source/macaw-campaigns/node_modules/webpack/node_modules/tapable/lib/Tapable.js:26:37)

I found this solution on a Github issue:

我在 Github 问题上找到了这个解决方案:

https://github.com/webpack/karma-webpack/issues/65

https://github.com/webpack/karma-webpack/issues/65

Here is are the updated lines in my package.json:

这是我的更新行package.json

"karma": "^0.13.3",
"karma-chrome-launcher": "^0.2.0",
"karma-jasmine": "^0.3.6",
"karma-webpack": "^1.7.0",

Hope this helps.

希望这可以帮助。

回答by VadimB

You should upgrade "karma" and "karma-webpack" packages. Had similar exception, upgrading to next versions solved this:

您应该升级“karma”和“karma-webpack”包。有类似的例外,升级到下一个版本解决了这个问题:

"karma": "0.13.18",
"karma-webpack": "1.7.0"