我在使用这个 webpack 文件时遇到错误。
这是 webpack 文件:
const path = require('path');
module.exports = {
target: 'node',
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'build')
},
module: {
rules: [
{
test: /\.js?$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
presets: [
'react',
'stage-0',
['env', { targets: { browsers: ['last 2 versions']}}]
]
}
}
]
}
}
这是错误信息:
Invalid configuration object. Webpack has been initialised using a
configuration object that does not match the API schema.
- configuration.context: The provided value
"C:\\Users\\}\\Desktop\\Node\\HelloWorld!\\new" contains exclamation mark
(!) which is not allowed because it's reserved for loader syntax.
-> The base directory (absolute path!) for resolving the `entry` option. If
`output.pathinfo` is set, the included pathinfo is shortened to this
directory.
- configuration.output.path: The provided value
"C:\\Users\\}\\Desktop\\Node\\HelloWorld!\\new\\build" contains
exclamation mark (!) which is not allowed because it's reserved for loader
syntax.
-> The output directory as **absolute path** (required).
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! new@1.0.0 dev:build:server: `webpack --config
webpack.server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the new@1.0.0 dev:build:server script.
npm ERR! This is probably not a problem with npm. There is likely
additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\}\AppData\Roaming\npm-cache\_logs\2019-01-
08T16_11_48_069Z-debug.log
最佳答案
同样的错误。问题似乎出在您的文件夹路径中。它不得包含感叹号 (!)。 更改文件夹“HelloWorld!”只是没有感叹号的“HelloWorld”。
希望这能解决问题。
关于webpack-dev-server - 无效的配置对象 : webpack. server.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54096083/