严格按照webpack网站上的入门指南,我在构建时遇到此错误:
./src/index.js中的错误找不到模块:错误:无法解析@。/ src / index中的'C:\ Users \ Dominik \ Desktop \ tutorial'中的'css-loader'。 js 2:0-21 webpack.config.js
css-loader
已本地安装。它已在package.json
中注册。我在做什么错了?
const path = require("path");
module.exports = {
entry: "./src/index.js",
output: {
filename: "bundle.js",
path: path.resolve(__dirname, "dist")
},
module: {
rules: [
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
}
]
}
};
package.json
{
"name": "tutorial",
"version": "1.0.0",
"description": "",
"private": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack"
},
"author": "",
"license": "ISC",
"devDependencies": {
"css-loader": "^3.4.0",
"style-loader": "^1.1.1",
"webpack": "^4.41.4",
"webpack-cli": "^3.3.10"
},
"dependencies": {
"lodash": "^4.17.15"
}
}
index.js
import _ from "lodash";
import "./style.css";
function component() {
const element = document.createElement("div");
element.innerHTML = _.join(["Hello", "webpack"], " ");
element.classList.add("hello");
return element;
}
document.body.appendChild(component());
style.css
.hello {
color: red;
}
答案 0 :(得分:1)
尝试重新运行npm install --save-dev css-loader
。您可以在node_modules
文件夹中看到它吗?
编辑
卸载并重新安装该模块已对其进行了修复:
npm remove css-loader && npm install --save-dev css-loader