我使用webpack和mocha-loader插件。我有一个控制台错误:
Uncaught TypeError: (intermediate value).nextTick is not a function(…)
webpack.config.js:
...
target: 'web',
entry: {
app: [path.resolve(applicationConfig.source.path, 'app.js')],
vendors: [path.resolve(applicationConfig.source.path, 'vendors.js')],
testing: 'mocha!' + path.resolve(applicationConfig.source.path, 'testing.js')
},
...
我从/testing.html文件运行测试 testing.html:
<!DOCTYPE html>
<html>
<head>
<title>Mocha</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<script src="./testing.js"></script>
</body>
</html>
Mocha-loader有start.js文件:
process.nextTick(function() {
delete require.cache[module.id];
if(typeof window !== "undefined" && window.mochaPhantomJS)
mochaPhantomJS.run();
else
mocha.run();
});
在webpack工作之后,它看起来像这样:
({"env":{"NODE_ENV":"development"}}).nextTick(function() {
delete __webpack_require__.c[module.id];
if(typeof window !== "undefined" && window.mochaPhantomJS)
mochaPhantomJS.run();
else
mocha.run();
});
我可以使用polyfill with process.nextTick(https://gist.github.com/WebReflection/2953527)但是我不能在替换过程变量之后。
答案 0 :(得分:0)
我替换了
new webpack.DefinePlugin({
process: {
env: {
NODE_ENV: JSON.stringify('development')
}
},
__DEV__: true
}),
到
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('development')
},
__DEV__: true
}),
代码工作