简体   繁体   English

React-Scripts:为什么我不能通过引用 node_modules 文件夹来导入 .scss 文件

[英]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.

相关问题 sh: /Users/mac/Desktop/LOGIC/node_modules/.bin/react-scripts: /bin/sh^M: 错误的解释器:没有这样的文件或目录 - sh: /Users/mac/Desktop/LOGIC/node_modules/.bin/react-scripts: /bin/sh^M: bad interpreter: No such file or directory 我是否必须将我创建并想要导入的任何脚本/模块放置在 node_modules 文件夹中? - Do I have to place any scripts/modules I create and want to import within the node_modules folder? 未找到或无法读取要导入的文件:node_modules/bootstrap/scss/functions - File to import not found or unreadable: node_modules/bootstrap/scss/functions `.babelrc`文件在嵌套的node_modules文件夹中找不到预设 - `.babelrc` file can't find presets in a nested node_modules folder 为什么我不能使用SystemJS直接从node_modules导入? - Why I can not import directly from node_modules using SystemJS? 〜导入scss的符号是在Angular 6中的node_modules中搜索 - ~ sign to import scss is searching inside node_modules in Angular 6 从 ember 插件中的 node_modules 导入 scss - Import scss from node_modules within ember addon 从node_modules导入select2 scss - import select2 scss from node_modules 我可以将 node_modules 文件夹移动到另一个项目吗? - Can i move my node_modules folder to another project? 使用CopyWebpackPlugin如何在不创建node_modules文件夹的情况下将文件从node_modules复制到文件夹中 - Using CopyWebpackPlugin how can I copy files out of node_modules into a folder without it creating a node_modules folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM