简体   繁体   English

Node.js Sass 版本 7.0.0 与 ^4.0.0 不兼容 || ^5.0.0 || ^6.0.0

[英]Node.js Sass version 7.0.0 is incompatible with ^4.0.0 || ^5.0.0 || ^6.0.0

I used Node.js v16.13.1 and created a React application.我使用 Node.js v16.13.1 并创建了一个 React 应用程序。 I tried to use Sass , but when I tried to run it, I got this error:我尝试使用Sass ,但是当我尝试运行它时,出现了这个错误:

Node Sass version 7.0.0 is incompatible with ^4.0.0 || Node Sass 版本 7.0.0 与 ^4.0.0 不兼容 || ^5.0.0 || ^5.0.0 || ^6.0.0 ^6.0.0

If you want to use SCSS and Sass in your React app, try to do as below and your files will be correctly compiled:如果你想在你的 React 应用程序中使用SCSSSass ,尝试如下操作,你的文件将被正确编译:

  1. First remove node-sass :首先删除node-sass
 yarn remove node-sass # if you use npm npm uninstall node-sass
  1. Then install sass instead of node-sass :然后安装sass而不是node-sass
 yarn add -D sass # if you use npm npm i -D sass

Don't use node-sass anymore不再使用 node-sass

node-sass is deprecated. node-sass已弃用。 Instead use sass .而是使用sass You can uninstall the old and install the new one:您可以卸载旧的并安装新的:

npm uninstall node-sass
npm install sass


But if you prefer to use node-sass但是如果你更喜欢使用node-sass

You can use the following table to install the appropriate version node-sass for your installed node version which you can check by the command node --version .您可以使用下表为已安装的节点版本安装适当的node-sass版本,您可以通过命令node --version检查。

npm install node-sass@(your version)

在此处输入图像描述

I had the same problem with sass and I run this commands like below but none of them works.我对sass有同样的问题,我运行如下命令,但它们都不起作用。

npm uninstall node-sass
npm install sass

So finally I take a look at my package.json and I saw that I installed sass-loader so I uninstall and install that and the problem is fixed.所以最后我看看我的package.json我看到我安装了sass-loader所以我卸载并安装它并且问题得到解决。 You can use commands below for that:您可以为此使用以下命令:

npm uninstall sass-loader
npm install sass-loader

I figured out this issue using node-sass version 4.14.1 with the following commands:我使用node-sass版本4.14.1和以下命令解决了这个问题:

  • With npm配npm
 npm uninstall node-sass npm install node-sass@4.14.1
  • With yarn用纱
yarn remove node-sass yarn add node-sass@4.14.1

You can just switch to sass in your package.json, like so:您可以在 package.json 中切换到sass ,如下所示:

 "node-sass": "npm:sass@^1.49.9",

This way React still asks for node-sass after removing it and rreplacing with sass so you can alias it like this and now React will use sass这样,React 在删除它并用sass后仍然要求node-sass ,所以你可以像这样给它起别名,现在 React 将使用sass

Just remove the node-sass and install sass instead.只需删除node-sass并安装sass

  1. delete node_modules directory.删除 node_modules 目录。
  2. run yarn remove node-sass运行yarn remove node-sass
  3. run yarn add sass运行yarn add sass

or with npm或与 npm

  1. delete node_modules directory.删除 node_modules 目录。
  2. run npm uninstall --save node-sass运行npm uninstall --save node-sass
  3. run npm install --save sass运行npm install --save sass

You can simply do npm install node-sass@6.0 .你可以简单地做npm install node-sass@6.0

This is because Node.js 16 is compatible with node-sass version 6.0.这是因为 Node.js 16 与 node-sass 版本 6.0 兼容。

I got the same issue.我遇到了同样的问题。 At the time of installing 'node-sass', my Node.js version is 15.在安装“node-sass”时,我的 Node.js 版本是 15。

After downgrading node version node-12 and installed node-12 related ' node-sass ' it's worked fine.降级节点版本 node-12 并安装与 node-12 相关的“ node-sass ”后,它工作正常。

node -v

# Output: v15.2.0

nvm use 12.18.3

Now using node v12.18.3 (npm v6.14.6)现在使用节点 v12.18.3 (npm v6.14.6)

node -v

# Output: v12.8.3

npm install node-sass@4.14.1

To make sure it's working properly, add some abc.sass file.为了确保它正常工作,添加一些abc.sass文件。 And write styles and import it on the component.并写入 styles 并在组件上导入。

There is a lot of misinformation in the replies to this question and it's the first thing to shows up in Google:对这个问题的回复中有很多错误信息,这是在 Google 中出现的第一件事:

If you see this problem in your application, the culprit is NOT the node-sass or Node.js version.如果您在应用程序中看到此问题,则罪魁祸首不是node-sass或 Node.js 版本。 It's the sass-loader issue and that's the library you need to upgrade since older versions are not compatible with the newer node-sass .这是sass-loader问题,这是您需要升级的库,因为旧版本与较新的node-sass不兼容。

Based on input and the following steps, I got it working for shopware6 while build-administration.sh where a similar error occurred:根据输入和以下步骤,我让它为 shopware6 工作,而build-administration.sh发生了类似的错误:

Error: Node Sass version 7.0.1 is incompatible with ^4.0.0.错误:节点 Sass 版本 7.0.1 与 ^4.0.0 不兼容。

ERROR in ./src/app/component/base/sw-button/sw-button.scss (./node_modules/mini-css-extract-plugin/dist/loader.js!./node_modules/css-loader/dist/cjs.js??ref--15-2!./node_modules/sass-loader/lib/loader.js??ref--15-3!./src/app/component/base/sw-button/sw-button.sc)
Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from ./node_modules/sass-loader/lib/loader.js):
Error: Node Sass version 7.0.1 is incompatible with ^4.0.0.
    at getRenderFuncFromSassImpl (/var/ww

Checking the currently installed node-sass version and uninstalling and installing the "lower" version:检查当前安装的 node-sass 版本并卸载并安装“较低”版本:

npx node-sass -v results in:
node-sass: 7.0.1
libsass 3.5.5

npm uninstall node-sass
npm install node-sass@4.14.1

npx node-sass -v results in:
node-sass       4.14.1  (Wrapper)       [JavaScript]
libsass         3.5.5   (Sass Compiler) [C/C++]

Before that, I checked the mentioned version numbers in a complete htdocs folder:在此之前,我在一个完整的htdocs文件夹中检查了提到的版本号:

.../htdocs$ find . -iname '*package.json*'  | xargs  grep node-sass {}

In the resulting (huge) list, the following node-sass versions are found:在生成的(巨大的)列表中,找到了以下 node-sass 版本:

....nistration/Resources/app/administration/node_modules/node-sass/package.json:    "lint": "eslint bin/node-sass lib scripts test",
./vendor/shopware/administration/Resources/app/administration/node_modules/sass-loader/package.json:    "node-sass": "^4.5.0",
grep: {}: Datei oder Verzeichnis nicht gefunden
./vendor/shopware/administration/Resources/app/administration/node_modules/stylelint-webpack-plugin/package.json:    "node-sass",
./vendor/shopware/administration/Resources/app/administration/build/nuxt-component-library/package.json:        "node-sass": "4.12.0",
./vendor/shopware/administration/Resources/app/administration/package.json:    "node-sass": "^7.0.1",    <<<<<< THIS ONE !!
./vendor/shopware/administration/Resources/app/administration/package.jsonORIG-2021-12-29:    "node-sass": "^7.0.1",

After uninstalling and install node-sass@4.14.1 and changing the marked line from卸载并安装 node-sass@4.14.1 并将标记的行从

"node-sass": "^7.0.1",

to

"node-sass": "^4.0.1",

it compiled and build-administration.sh (a shopware6 thing...) succeeded.它编译并build-administration.sh (一个 shopware6 的东西......)成功了。

Time: 58913ms
Entrypoint commons = static/js/runtime.js static/css/vendors-node.css static/js/vendors-node.js static/js/vendors-node.js.map static/js/commons.js
Entrypoint app = static/js/runtime.js static/css/vendors-node.css static/js/vendors-node.js static/js/vendors-node.js.map static/css/app.css static/js/app.js
Entrypoint storefront = static/js/runtime.js static/css/vendors-node.css static/js/vendors-node.js static/js/vendors-node.js.map static/css/storefront.css static/js/storefront.js
Entrypoint payone-payment = static/js/runtime.js static/css/vendors-node.css static/js/vendors-node.js static/js/vendors-node.js.map static/css/payone-payment.css static/js/payone-payment.js
Entrypoint wbm-tag-manager-ecomm = static/js/runtime.js static/css/vendors-node.css static/js/vendors-node.js static/js/vendors-node.js.map static/css/wbm-tag-manager-ecomm.css static/js/wbm-tag-manager-ecomm.js
   3909 modules
build-administration.sh: 14: build-administration.sh: [[: not found
Copying files for bundle: FrameworkBundle
Copying files for bundle: MonologBundle
Copying files for bundle: SwiftmailerBundle
Copying files for bundle: SensioFrameworkExtraBundle
Copying files for bundle: TwigBundle
Copying files for bundle: EnqueueBundle
Copying files for bundle: EnqueueAdapterBundle
Copying files for bundle: Framework
Copying files for bundle: System
Copying files for bundle: Content
Copying files for bundle: Checkout
Copying files for bundle: Administration
Copying files for bundle: Storefront
Copying files for bundle: Elasticsearch
Copying files for bundle: SwagPlatformDemoData
Copying files for bundle: Netzp6AddressValidator
Copying files for bundle: PayonePayment
Copying files for bundle: WbmTagManagerEcomm
Copying files for bundle: DbalKernelPluginLoader


 [OK] Successfully copied all bundle files

In my case #first uninstalled using npm npm uninstall node-sass Then install #using npm npm i -D sass在我的例子中#first uninstalled using npm npm uninstall node-sass 然后安装#using npm npm i -D sass

I got this error two months back.两个月前我收到了这个错误。 I tried each and every solution I can probably find.我尝试了所有可能找到的解决方案。

Check whether you have created multiple React projects on the desktop.检查您是否在桌面上创建了多个 React 项目。 I did the same and started facing this issue.我做了同样的事情并开始面对这个问题。 Combine all of them inside a single folder to get rid of the error.将它们全部组合在一个文件夹中以消除错误。 It worked for me.它对我有用。 Please try this if you are making the same mistake.如果您犯了同样的错误,请尝试此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM