[英]Multiple errors using sass-loader in webpack + react
I've been configuring for several hours and the problem keeps going. 我已经配置了几个小时,问题一直存在。 I've searched over the Internet and couldn't find solve it.
我已经在Internet上搜索了,找不到解决方法。 Here are the three types of error I get
这是我遇到的三种错误
ERROR in ./src/styles/app.scss Module not found: Error: Can't resolve 'fonts/american-typewriter.woff2' in '/Users/liumy/Documents/xxx/www/src/styles' @ ./src/styles/app.scss 7:371-413 @ ./src/index.js @ multi (webpack)-dev-server/client?
./src/styles/app.scss中的错误找不到模块:错误:无法解析'/ Users / liumy / Documents / xxx / www / src / styles'@ ./中的'fonts / american-typewriter.woff2' src / styles / app.scss 7:371-413 @ ./src/index.js @多(webpack)-dev-server / client? http://localhost:3000 ./src/index.js
http:// localhost:3000 ./src/index.js
ERROR in ./src/PageHome/style.scss Module not found: Error: Can't resolve 'assets/background.jpg' in '/Users/liumy/Documents/xxx/www/src/PageHome' @ ./src/PageHome/style.scss 7:220-252 @ ./src/PageHome/index.js @ ./src/index.js @ multi (webpack)-dev-server/client?
找不到./src/PageHome/style.scss模块中的错误:错误:无法解析'/ Users / liumy / Documents / xxx / www / src / PageHome'@ ./src/中的'assets / background.jpg' PageHome / style.scss 7:220-252 @ ./src/PageHome/index.js @ ./src/index.js @多(webpack)-dev-server / client? http://localhost:3000 ./src/index.js
http:// localhost:3000 ./src/index.js
ERROR in ./src/components/NavBar/style.scss Module build failed (from ./node_modules/sass-loader/lib/loader.js): var colors = require('./colors');
./src/components/NavBar/style.scss中的错误模块构建失败(来自./node_modules/sass-loader/lib/loader.js):var colors = require('./ colors'); Invalid CSS after "v": expected 1 selector or at-rule, was "var colors = requir" in /Users/liumy/Documents/xxx/www/node_modules/colors/lib/index.js (line 1, column 1) @ ./src/components/NavBar/index.js 17:13-36 @ ./src/index.js @ multi (webpack)-dev-server/client?
“ v”后的CSS无效:预期的1个选择器或规则,是/Users/liumy/Documents/xxx/www/node_modules/colors/lib/index.js(第1行,第1列)中的“ var colors = requir” @ ./src/components/NavBar/index.js 17:13-36 @ ./src/index.js @多(webpack)-dev-server / client? http://localhost:3000 ./src/index.js
http:// localhost:3000 ./src/index.js
And here is my webpack config: 这是我的webpack配置:
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: ["node_modules"],
use: [{ loader: "babel-loader" }]
},
{
test: [
/\.(png|jpg|gif|woff|woff2|eot|ttf|svg)/,
/\/typefaces\/.*\.svg/
],
use: [{ loader: "file-loader" }]
},
{
test: /\.s?css$/,
use: [
{
loader: "css-loader",
options: {
modules: true,
camelCase: true,
localIdentName: "[name]__[local]__[hash:base64:5]",
minimize: true,
sourceMap: true,
importLoaders: 1
}
},
{
loader: "postcss-loader"
},
{
loader: "resolve-url-loader"
},
{
loader: "sass-loader",
options: {
sourceMap: true,
includePaths: [path.resolve(SRC_PATH, "styles")]
}
}
]
}
]
},
What could the problem possibly be? 可能是什么问题? Thanks!
谢谢!
Have you tried to add the path to the resources that are not found to sass-loader
's includePaths
? 您是否尝试将路径添加到
sass-loader
的includePaths
找不到的资源?
includePaths: [path.resolve(SRC_PATH, "styles"), path.resolve(SRC_PATH, "path/to/assets")]
Where path/to/assets/
is part of path/to/assets/fonts/american-typewriter.woff2
其中
path/to/assets/
是path/to/assets/fonts/american-typewriter.woff2
Or try adding includePaths
to css-loader
since you get the error from the webpack-dev-server
或尝试将
includePaths
添加到css-loader
因为您从webpack-dev-server
得到了错误
The problem arose after I installed some libraries through yarn add
, even though I was not using them but it seems their existence in node_modules messed up with sass-loader. 在我通过
yarn add
安装了一些库之后出现了问题,即使我没有使用它们,但似乎它们在node_modules中的存在使sass-loader混乱了。 I'm not really sure if that's really the problem, but after removing those libraries the Webpack is able to compile. 我不确定这是否是真正的问题,但是在删除了那些库之后,Webpack便可以编译了。 I hope my experience can provide some insight to anyone who's facing the same problem - consider removing some libraries that you're not using.
我希望我的经验可以为遇到相同问题的任何人提供一些见识-考虑删除一些您不使用的库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.