[英]React-Scripts: Why can't I import a .scss file by referencing node_modules folder
I have a project created by 'create-create-app' cli, and I've recently updated from Node 12 to 16 and react-scripts 2 to 5. Since then, I've been getting this error.我有一个由'create-create-app' cli 创建的项目,我最近从节点 12 更新到 16 和 react-scripts 2 到 5。从那时起,我一直收到此错误。
ERROR in ./src/assets/main.scss (./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[0].oneOf[7].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].oneOf[7].use[2]!./node_modules/resolve-url-loader/index.js??ruleSet[1].rules[0].oneOf[7].use[3]!./node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[0].oneOf[7].use[4]!./src/assets/main.scss)
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Can't find stylesheet to import.
╷
9 │ @import "node_modules/bootstrap/scss/functions";
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
╵
node_modules/shards-ui/src/scss/shards.scss 9:9 @import
src/styles/shards-dashboards.scss 15:9 @import
src/assets/main.scss 4:9 root stylesheet
The shards-ui is a dependency of my package.json. shards-ui 是我的 package.json 的依赖项。 The
.shards.scss
file of shards-ui dependency is importing a file from its local node_modules. shards-ui 依赖的
.shards.scss
文件正在从其本地 node_modules 导入文件。
@import "node_modules/bootstrap/scss/functions";
Also, installing using yarn 1.22.19
doesn't give me this error.此外,使用
yarn 1.22.19
安装不会给我这个错误。 But npm 8.11.0
does.但是
npm 8.11.0
可以。
To remove the error, I changed为了消除错误,我改变了
@import "node_modules/bootstrap/scss/functions";
to至
@import "~bootstrap/scss/functions";
I would like to understand why yarn doesn't present any error, and if changing the import is the best fix for it.我想了解为什么 yarn 不会出现任何错误,以及更改导入是否是最好的解决方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.