webpack-dev-server - 无效的配置对象 : webpack. server.js

标签 webpack-dev-server

我在使用这个 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/

相关文章:

reactjs - React Router (v3) 重定向不重定向到新位置

javascript - webpack-dev-server 得到黑屏

javascript - webpack 热模块替换不起作用

node.js - Webpack 输出中的 Mimetype 错误(使用 knockout )

javascript - 无需构建步骤即可启动 webpack dev server

webpack - 如何在Vue应用程序的头部有条件地添加代码

javascript - 为什么我在 React.js + GraphQL : Module build failed: SyntaxError: Unexpected token (10:6) 中收到此错误

reactjs - 我的 npm start for React 教程项目无法正常工作

javascript - 路径更改时 Webpack 从错误的 URL 加载

javascript - 将组件直接渲染到模板中