【发布时间】:2021-07-02 11:02:11
【问题描述】:
我目前正在学习 webpack,但我无法弄清楚这一点。我真的很感激一些帮助。 我收到此错误:
ERROR in ./src/style.css 1:5
Module parse failed: Unexpected token (1:5)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> body {
| background-color: red;
| color: white;
@ ./src/index.js 1:0-20
我已经导入了 css-loader 和 style-loader:npm i -D css-loader style-loader。 package.json 文件如下所示:
{
"name": "webpack-styles",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"css-loader": "^5.2.6",
"style-loader": "^3.0.0",
"webpack": "^5.42.0",
"webpack-cli": "^4.7.2"
}
}
webpack.config.js 看起来像这样:
module.exports = {
module: {
rules: [
{
test: /\.css$/i,
use: [ "css-loader", "style-loader"],
},
],
},
};
我已将 css 文件导入 index.js,如下所示:
import "./style.css"
谁能看到问题可能是什么? 谢谢!
【问题讨论】:
标签: webpack css-loader