“模块"不允许错误 [英] "Modules" is not allowed Error
问题描述
Webpack 2 带有新的解析设置,当我尝试修改 config 中的设置时,如下所示,webpackValidator 抛出一个错误说
Webpack 2 comes with the new resolve setting and when I try to modify the setting in config, as follows, webpackValidator throws an error saying
不允许使用模块""
const config = webpackValidator({
context: resolve('src'),
entry: './app.js',
output: {
filename: 'bundle.js',
path: resolve('dist'),
publicPath: '/dist/',
pathinfo: ifNotProd(),
},
devtool: ifProd('source-map', 'eval'),
module: {
loaders: [
{
test: /\.js$/,
loaders: ['babel'],
exclude: /node_modules/
}
]
},
resolve: {
extensions: ['.js'],
modules: [
resolve(__dirname, 'src'),
resolve(__dirname, 'node_modules')
]
},
plugins: [
new DashboardPlugin()
]
})
推荐答案
如 webpack-validator 项目的自述文件 (npm & github),你应该认真考虑给使用这个包...
As mentioned on the webpack-validator project's readme (npm & github), you should seriously consider giving up the use of this package...
注意:webpack v2 内置了配置验证.因此,webpack-validator 不太可能进行重大更改.虽然拉取请求将被审查并可以合并,但项目维护人员不太可能在项目维护上投入大量精力.
Note: webpack v2 has built-in validation for configuration. Due to this, webpack-validator is unlikely to make significant changes. While pull requests will be reviewed and can be merged, project maintainers are unlikely to put a lot of much effort into the maintenance of the project.
我遇到了同样的问题,最后放弃了它的使用:Webpack 2 引入了 webpack-validator 项目肯定不会遵循的重大更改.Webpack 2 中新的内置配置验证现在已经足够好了.
I had the same issue and finally gave up its use : Webpack 2 introduced breaking changes that surely won't be followed by the webpack-validator project. The new built-in validation for configuration in Webpack 2 is now good enough.
顺便说一下,您的配置可能需要一些改进:
By the way, your config may need a few improvements :
const config = {
context: resolve('src'),
entry: './app.js',
output: {
filename: 'bundle.js',
path: resolve('dist'),
publicPath: '/dist/',
pathinfo: ifNotProd(),
},
devtool: ifProd('source-map', 'eval'),
module: {
rules: [
{
test: /\.js$/,
use: ['babel-loader'],
exclude: /node_modules/
}
]
},
resolve: {
extensions: ['.js'],
modules: [
resolve(__dirname, 'src'),
resolve(__dirname, 'node_modules')
]
},
plugins: [
new DashboardPlugin()
]
}
module.loaders
变成module.rules
module.loaders.loaders
变成module.rules.use
- 您不能再使用快捷方式babel"代替babel-loader",除非您指定它(
resolveLoader.moduleTemplates
属性). module.loaders
becomesmodule.rules
module.loaders.loaders
becomesmodule.rules.use
- You can't use the shortcut 'babel' instead of 'babel-loader' any more, unless you specify it (
resolveLoader.moduleTemplates
property).
这篇关于“模块"不允许错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!