错误:Node Sass尚不支持您当前的环境。

7
当我在Fedora 32中使用命令yarn start启动我的React项目时,它显示以下错误:
./src/style/base.scss (./node_modules/css-loader/dist/cjs.js??ref--6-oneOf-5-1!./node_modules/postcss-loader/src??postcss!./node_modules/resolve-url-loader??ref--6-oneOf-5-3!./node_modules/sass-loader/dist/cjs.js??ref--6-oneOf-5-4!./src/style/base.scss)
Error: Node Sass does not yet support your current environment: Linux 64-bit with Unsupported runtime (93)
For more information on which environments are supported please see:
https://github.com/sass/node-sass/releases/tag/v4.14.1

我的当前的Node版本是:

[dolphin@MiWiFi-R4CM-srv]~/Documents/GitHub/react-admin% nvm list
        v8.17.0
       v10.24.1
->     v16.13.0
        v17.2.0
         system
default -> 8 (-> v8.17.0)

我已经尝试了不同版本的node,但并没有解决这个问题,为什么会出现这种情况?应该怎么做才能解决这个问题?在package.json中,我没有找到任何关于node-sass的包依赖。以下是package.json文件:

{
    "name": "react-admin",
    "version": "0.1.0",
    "private": true,
    "dependencies": {
        "@ant-design/compatible": "1.0.8",
        "animate.css": "^3.7.2",
        "antd": "^4.0.0",
        "axios": "^0.19.0",
        "braft-editor": "^2.3.8",
        "echarts": "^4.4.0",
        "is-core-module": "2.2.0",
        "moment": "2.29.1",
        "nprogress": "^0.2.0",
        "react": "^17.0.2",
        "react-dom": "^17.0.2",
        "react-highlight-words": "0.17.0",
        "react-loadable": "^5.5.0",
        "react-redux": "^7.1.1",
        "react-router-dom": "^5.1.1",
        "react-scripts": "^3.2.0",
        "redux": "^4.0.4",
        "redux-logger": "3.0.6",
        "redux-promise-middleware": "^6.1.2",
        "redux-thunk": "^2.3.0",
        "screenfull": "^5.0.0"
    },
    "scripts": {
        "start": "react-app-rewired start",
        "build": "CI=false && react-app-rewired build",
        "test": "react-app-rewired test",
        "eject": "react-scripts eject"
    },
    "eslintConfig": {
        "extends": "react-app"
    },
    "browserslist": {
        "production": [
            ">0.2%",
            "not dead",
            "not op_mini all"
        ],
        "development": [
            "last 1 chrome version",
            "last 1 firefox version",
            "last 1 safari version"
        ]
    },
    "husky": {
        "hooks": {
            "pre-commit": "lint-staged"
        }
    },
    "lint-staged": {
        "src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
            "node_modules/.bin/prettier --write",
            "git add"
        ],
        "src/**/*.{css,scss,less,json,html,md,markdown}": [
            "node_modules/.bin/prettier --write",
            "git add"
        ]
    },
    "devDependencies": {
        "@babel/helper-builder-react-jsx": "^7.12.13",
        "babel-plugin-import": "^1.12.2",
        "customize-cra": "^0.8.0",
        "husky": "^3.0.9",
        "lint-staged": "^9.4.2",
        "sass": "1.37.0",
        "prettier": "^1.18.2",
        "react-app-rewired": "^2.1.4"
    }
}
3个回答

12

第一种解决方案

确保你的node.js版本不要高于推荐版本。如果高于,降级处理,你可以使用npm中的n包进行降级操作。

npm i -g n
n stable
# if one of the commands does not pass, you may need to use sudo
sudo npm install -g n
sudo n 14

如果你想使用sass包而不是已经被弃用的node-sass,那么你需要在终端中运行以下命令:

npm uninstall node-sass --save
npm install sass --save

第二种解决方案

如果出于某些原因您需要或想要使用node-sass,您应该将nodejs版本降级到像v14这样的版本。为此,您可以使用npm中的n包:

npm install -g n
n 14
# if one of the commands does not pass, you may need to use sudo
sudo npm install -g n
sudo n 14

6

这是一个与Node版本不兼容的常见node-sass版本兼容性问题。

快速解决方案:

卸载并重新安装node-sass,它会自行找到缺失的二进制文件。

npm uninstall --save-dev node-sass
npm install --save-dev node-sass

永久解决方案:

如果使用上述命令无法解决问题,则可能是您的节点版本存在问题。请检查您的节点版本是否支持node-sass版本。选择一个稳定的节点版本并重复上述命令以解决此问题。

下面是节点与node-sass的兼容性表:

NodeJS | Supported node-sass version | Node Module
Node 19     8.0                         111
Node 18     8.0                         108
Node 17     7.0+                        102
Node 16     6.0+                        93
Node 15     5.0+                        88
Node 14     4.14+                       83
Node 13     4.13+, <5.0                 79
Node 12     4.12+                       72
Node 11     4.10+, <5.0                 67
Node 10     4.9+, <6.0                  64
Node 8      4.5.3+, <5.0                57
Node <8     <5.0                        <57

如果问题仍未解决,请检查node-sass支持的环境列表:- https://github.com/sass/node-sass/releases/

1
在我想要使用的特定节点版本(在我的情况下是Node V18)上,卸载并重新安装node-sass对我有用。谢谢@Balram Singh。 - Solomon Sunday

1

当我部署一个已经存在的应用程序时,遇到了同样的问题。

降低Node版本可以解决这个问题。

在开发该应用程序时使用了 Node v14.19.2,本地安装了 Node 16.18.0 版本。node-sass 根据以下方案依赖于 Node 版本:

┌────┬─────────┬─────────────────────────────┬─────────────┐
│    │    A    │              B              │      C      │
├────┼─────────┼─────────────────────────────┼─────────────┤
│  1 │ NodeJS  │ Supported node-sass version │ Node Module │
│  2 │ Node 19 │ 8.0+                        │ 111         │
│  3 │ Node 18 │ 8.0+                        │ 108         │
│  4 │ Node 17 │ 7.0+, <8.0                  │ 102         │
│  5 │ Node 16 │ 6.0+                        │ 93          │
│  6 │ Node 15 │ 5.0+, <7.0                  │ 88          │
│  7 │ Node 14 │ 4.14+                       │ 83          │
│  8 │ Node 13 │ 4.13+, <5.0                 │ 79          │
│  9 │ Node 12 │ 4.12+, <8.0                 │ 72          │
│ 10 │ Node 11 │ 4.10+, <5.0                 │ 67          │
│ 11 │ Node 10 │ 4.9+, <6.0                  │ 64          │
│ 12 │ Node 8  │ 4.5.3+, <5.0                │ 57          │
│ 13 │ Node <8 │ <5.0                        │ <57         │
└────┴─────────┴─────────────────────────────┴─────────────┘

根据表格中的依赖关系,我安装了Node 14版本,对应于package.json中的node-sass版本,一切都正常运行。

"node-sass": "^4.14.1",

我尝试更改node-sass版本,但没有成功。只有通过降级Node版本才能解决问题。

有时,在更改Node版本后,您需要运行以下命令:

npm rebuild node-sass

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接