SassError: 在ReactJS中未定义变量“primary”: $primary-text-emphasis-dark

huangapple go评论82阅读模式
英文:

SassError: Undefined variable."primary": $primary-text-emphasis-dark in reactjs

问题

在构建我的React应用程序时,我遇到了如图片所示的错误,并且使用了"sass": "1.32.1"和Bootstrap版本5.0.2。在执行"npm start"时没有任何错误,但在构建过程中(在Jenkins中运行npm run build时),发生了错误。

SassError: 在ReactJS中未定义变量“primary”: $primary-text-emphasis-dark

英文:

While building my react app i got error as shown in picture and using "sass": "1.32.1" and bootstrap version 5.0.2. There is no any error while "npm start" but while building(npm run build in Jenkins), error occur.

SassError: 在ReactJS中未定义变量“primary”: $primary-text-emphasis-dark

答案1

得分: 7

Bootstrap 5.3.0(目前最新版本)新增了对暗模式和亮模式的支持。

我已经通过在我的主要 site.scss 文件中添加了名为 variables-dark.scss 的新的 Bootstrap 源文件(与 ReactJS 无关)来解决了相同的问题,这个文件紧随现有的 variables.scss

// site.scss
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/variables-dark";

更多详细信息可以在 Bootstrap Sass 版本 5.3 的文档中找到,链接在此

另外,如果你的 ReactJS 框架还不支持 Bootstrap 5.3,也许更简单的选择是在 package.json 文件中将 Bootstrap 版本锁定为 5.2.x

"dependencies": {
  ...
  "bootstrap": "~5.2.0"
  ...
},
英文:

Bootstrap 5.3.0 (latest at the moment) added support for dark and light modes.

I have solved the same problem (although unrelated to ReactJS) by adding new bootstrap source file variables-dark.scss, after already existing variables.scss in my main site.scss file:

// site.scss
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/variables-dark";

More details can be found in Bootstrap Sass documentation for version 5.3 here.

Other, perhaps easier option, if your ReactJS framework does not support Bootstrap 5.3 yet is to lock version of Bootstrap in package.json file to 5.2.x for now:

"dependencies": {
  ...
  "bootstrap": "~5.2.0"
  ...
},

答案2

得分: 1

我认为你需要将Bootstrap版本指定为5.2.x,不要超过。Bootstrap 5.3需要导入scss/variables-dark。

英文:

I think you need to specify Bootstrap version as 5.2.x, not above. Bootstrap 5.3 requires the import of scss/variables-dark

huangapple
  • 本文由 发表于 2023年6月1日 13:09:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76378815.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定