【问题标题】:Run script watch on latest version of webpack - Invalid configuration object在最新版本的 webpack 上运行脚本监视 - 无效的配置对象
【发布时间】:2021-03-14 20:34:32
【问题描述】:

运行此命令时

npm run-script watch

我有这个错误

npm ERR! command sh -c webpack --watch -d --output ./target/classes/static/built/bundle.js

还有这个

[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
 - configuration.devtool should match pattern "^(inline-|hidden-|eval-)?(nosources-)?(cheap-(module-)?)?source-map$".
   BREAKING CHANGE since webpack 5: The devtool option is more strict.
   Please strictly follow the order of the keywords in the pattern.

我的 webpack.config.js


var path = require('path');

module.exports = {
    entry: './src/main/js/App.js',
    cache: true,
    mode: 'development',
    output: {
        path: __dirname,
        filename: './src/main/resources/static/built/bundle.js'
    },
    module: {
        rules: [
            {
                test: path.join(__dirname, '.'),
                exclude: /(node_modules)/,
                use: [{
                    loader: 'babel-loader',
                    options: {
                        presets: ["@babel/preset-env", "@babel/preset-react"]
                    }
                }]
            },
            {
                test: /\.css$/,
                use: [
                    'style-loader',
                    'css-loader'
                ]
            },
            {
                test: /\.(png|svg|jpg|gif|eot|otf|ttf|woff|woff2)$/,
                use: [
                    {
                        loader: 'url-loader',
                        options: {}
                    }
                ]
            }
        ]
    }
};

知道为什么吗?

使用

"webpack": "^5.25.0", "webpack-cli": "^4.5.0"

谢谢,

【问题讨论】:

    标签: reactjs webpack devtools


    【解决方案1】:

    它写在你的错误中。您必须为“devtool”指定值。如果你想使用标志-d (short for --devtool),你必须指出它的值:https://webpack.js.org/configuration/devtool/#devtool

    【讨论】:

    • 我试过这个开发工具:'sourcemaps',但它没有帮助,我应该怎么做?
    • 检查第二个链接中的可能值列表。没有“sourcemaps”,但有“source-map”
    • 仍然无法使用:devtool: 'source-map',
    • 你把这个值放在哪里?在配置中还是在命令行中?如果您在配置中设置此值,您应该在您正在执行的 CLI 命令中删除 -d 标志。您正在调用“ webpack --watch -d --output ./target/classes/static/built/bundle.js”,它应该是“ webpack --watch -d source-地图 --output ./target/classes/static/built/bundle.js"
    • 我在命令行中运行它:npm run-script watch,在 package.json "watch": "webpack --watch -d source-map --output ./target/classes/static /built/bundle.js" --> 错误:[webpack-cli] 错误:未知选项 '--output' [webpack-cli] 运行 'webpack --help' 以查看可用的命令和选项
    猜你喜欢
    • 2021-04-10
    • 2020-05-28
    • 2022-01-12
    • 2017-08-20
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    相关资源
    最近更新 更多