javascript - 这个 Webpack 错误是什么,因为我在任何地方都找不到解决方案?
问题描述
在终端中我输入了这个命令:webpack -w
- configuration.module has an unknown property 'loaders'. These properties are valid:
object { defaultRules?, exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, generator?, noParse?, parser?, rules?, strictExportPresence?, strictThisContextOnImports?, unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, wrappedContextCritical?, wrappedContextRecursive?, wrappedContextRegExp? }
-> Options affecting the normal modules (`NormalModuleFactory`).
Did you mean module.rules or module.rules.*.use?
- configuration.output.path: The provided value "./dist" is not an absolute path!
-> The output directory as **absolute path** (required).```
解决方案
首先- 你把loaders
对象放在错误的地方,如错误所说
configuration.module 有一个未知的属性“loaders”。
如果您查看文档 loaders
在里面module.rules
(错误也提到了它 - 模块没有这样的键)但它也被弃用了。而是使用use
下面的示例
// webpack.config.js
module.exports = {
//...
module: {
rules: [
{
//...
use: [
'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 1,
},
},
],
},
],
},
};
第二
configuration.output.path:提供的值“./dist”不是绝对路径!
这基本上意味着您应该提供绝对路径。为此,请path
在顶部包含库并定义您的 iutput path.resolve()
- 更多信息在这里
const path = require('path');
module.exports = {
//...
output: {
path: path.resolve(__dirname, 'dist'),
},
};
PS 很难确定如果没有你这对你有帮助,webpack.config.js
所以我建议你下次也提供它的代码。
推荐阅读
- git - 测试与 git 的 SSH 连接提示密码
- javascript - 单击可触摸的不透明度后,我试图隐藏并显示反应本机日期选择器
- django - 使用 Django 的多文件上传无法按预期工作
- javascript - 如何在 fabricjs 版本 4 beta 中剪辑图像
- msbuild - directory.build.props :将存储在多级文件夹中的外部内容文件正确链接到 .csproj
- ios - 自动选择 SwiftUI 中的第 0 个项目
- java - MIP 中的来回通信是如何建立的?
- powerbi - PowerBI 查询性能
- python - 给定时间在python pandas中获取5分钟范围内的行
- pandas - 压缩目录中 gzip 文件的 pandas.read_csv