typescript webpack 4.1.1 -> configuration.module 有一个未知的属性 'loaders'。

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49203841/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 05:16:21  来源:igfitidea点击:

webpack 4.1.1 -> configuration.module has an unknown property 'loaders'.

javascripttypescriptwebpack

提问by Ogglas

I just updated webpack to 4.1.1and when I try to run it I get the following error:

我刚刚将 webpack 更新为4.1.1,当我尝试运行它时,出现以下错误:

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema. - configuration.module has an unknown property 'loaders'. These properties are valid: object { exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, noParse?, rules?, defaultRules?, unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, wrappedContextCritical?, wrappedContextRecursive?, wrappedContextRegExp?, strictExportPresence?, strictThisContextOnImports? } -> Options affecting the normal modules (NormalModuleFactory).

无效的配置对象。Webpack 已使用与 API 架构不匹配的配置对象进行初始化。- configuration.module 有一个未知的属性 'loaders'。这些属性是有效的: object { exprContextCritical?、exprContextRecursive?、exprContextRegExp?、exprContextRequest?、noParse?、rules?、defaultRules?、unknownContextCritical?、unknownContextRecursive?、unknownContextRegExp?、unknownContextRequest?、wrappedContextRecursive?、wrappedContextRecursive?、 ?,strictExportPresence?,strictThisContextOnImports? } -> 影响正常模块的选项 ( NormalModuleFactory)。

loaderslook like this and worked with webpack 3.11.0:

loaders看起来像这样并与webpack 3.11.0

module: {
    loaders: [
        { test: /\.tsx?$/, loader: ['ts-loader'] },
        { test: /\.css$/, loader: "style-loader!css-loader" },
        {
            test: /\.scss$/, use: [{
                loader: "style-loader" // creates style nodes from JS strings
            }, {
                loader: "css-loader" // translates CSS into CommonJS
            }, {
                loader: "sass-loader" // compiles Sass to CSS
            }]
        },
        { test: /\.(otf|ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/, loader: 'file-loader?name=./Scripts/dist/[name].[ext]' }
    ]
}

回答by Ogglas

Looked at an example loader for webpack 4.1.1:

查看 webpack 4.1.1 的示例加载器:

https://webpack.js.org/loaders/raw-loader/

https://webpack.js.org/loaders/raw-loader/

All I had to do was rename loadersto rules.

我所要做的就是重命名loadersrules.

module: {
    rules: [
        { test: /\.tsx?$/, loader: ['ts-loader'] },
        { test: /\.css$/, loader: "style-loader!css-loader" },
        {
            test: /\.scss$/, use: [{
                loader: "style-loader" // creates style nodes from JS strings
            }, {
                loader: "css-loader" // translates CSS into CommonJS
            }, {
                loader: "sass-loader" // compiles Sass to CSS
            }]
        },
        { test: /\.(otf|ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/, loader: 'file-loader?name=./Scripts/dist/[name].[ext]' }
    ]
}