无法在 Ubuntu 20 上安装“node-sass”

Posted

技术标签:

【中文标题】无法在 Ubuntu 20 上安装“node-sass”【英文标题】:Can't install 'node-sass' on Ubuntu 20 【发布时间】:2020-08-26 08:35:36 【问题描述】:

我使用 webpack 4、sass、pug 和 bemto。 Windows 上的模块工作正常,但在 Ubuntu 上:

npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! node-sass@4.14.1 postinstall: `node scripts/build.js`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the node-sass@4.14.1 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

我试过输入命令:

sudo npm install -g --unsafe-perm node-sass

>

(node:8310) [DEP0139] DeprecationWarning: Calling process.umask() with no arguments is prone to race conditions and is a potential security vulnerability.
(Use `node --trace-deprecation ...` to show where the warning was created)
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
/usr/local/bin/node-sass -> /usr/local/lib/node_modules/node-sass/bin/node-sass
npm WARN lifecycle The node binary used for scripts is /snap/bin/node but npm is using /snap/node/2725/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.

> node-sass@4.14.1 install /usr/local/lib/node_modules/node-sass
> node scripts/install.js

Cached binary found at /root/.npm/node-sass/4.14.1/linux-x64-83_binding.node

> node-sass@4.14.1 postinstall /usr/local/lib/node_modules/node-sass
> node scripts/build.js

Binary found at /usr/local/lib/node_modules/node-sass/vendor/linux-x64-83/binding.node
Testing binary
/snap/node/2725/bin/node: symbol lookup error: /usr/local/lib/node_modules/node-sass/vendor/linux-x64-83/binding.node: undefined symbol: _ZN2v816FunctionTemplate3NewEPNS_7IsolateEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEENS_5LocalIS4_EENSA_INS_9SignatureEEEiNS_19ConstructorBehaviorENS_14SideEffectTypeEPKNS_9CFunctionE
npm WARN You are using a pre-release version of node and things may not work as expected

npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! node-sass@4.14.1 postinstall: `node scripts/build.js`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the node-sass@4.14.1 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

更新:

我试过了: npm uninstall node-sass 后: npm install node-sass 没有帮助。

我试过了: npm install node-gyp全局,保存,保存开发

ERROR in ./src/sсss/critical.scss (./node_modules/css-loader??ref--5-1!./node_modules/sass-loader/lib/loader.js??ref--5-2!./src/sсss/critical.scss)
Module build failed (from ./node_modules/sass-loader/lib/loader.js):
Error: Cannot find module 'node-sass'
Require stack:
- /home/gorevanova/Documents/WebStorm/webpack-static/node_modules/sass-loader/lib/loader.js
- /home/gorevanova/Documents/WebStorm/webpack-static/node_modules/loader-runner/lib/loadLoader.js
- /home/gorevanova/Documents/WebStorm/webpack-static/node_modules/loader-runner/lib/LoaderRunner.js
- /home/gorevanova/Documents/WebStorm/webpack-static/node_modules/webpack/lib/NormalModule.js
- /home/gorevanova/Documents/WebStorm/webpack-static/node_modules/webpack/lib/NormalModuleFactory.js
- /home/gorevanova/Documents/WebStorm/webpack-static/node_modules/webpack/lib/Compiler.js
- /home/gorevanova/Documents/WebStorm/webpack-static/node_modules/webpack/lib/webpack.js
- /home/gorevanova/Documents/WebStorm/webpack-static/node_modules/webpack-dev-server/bin/webpack-dev-server.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1020:15)
    at Function.Module._load (internal/modules/cjs/loader.js:890:27)
    at Module.require (internal/modules/cjs/loader.js:1080:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/home/gorevanova/Documents/WebStorm/webpack-static/node_modules/sass-loader/lib/loader.js:3:14)
    at Module._compile (internal/modules/cjs/loader.js:1176:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1196:10)
    at Module.load (internal/modules/cjs/loader.js:1040:32)
    at Function.Module._load (internal/modules/cjs/loader.js:929:14)
    at Module.require (internal/modules/cjs/loader.js:1080:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at loadLoader (/home/gorevanova/Documents/WebStorm/webpack-static/node_modules/loader-runner/lib/loadLoader.js:18:17)
    at iteratePitchingLoaders (/home/gorevanova/Documents/WebStorm/webpack-static/node_modules/loader-runner/lib/LoaderRunner.js:169:2)
    at iteratePitchingLoaders (/home/gorevanova/Documents/WebStorm/webpack-static/node_modules/loader-runner/lib/LoaderRunner.js:165:10)
    at /home/gorevanova/Documents/WebStorm/webpack-static/node_modules/loader-runner/lib/LoaderRunner.js:176:18
    at loadLoader (/home/gorevanova/Documents/WebStorm/webpack-static/node_modules/loader-runner/lib/loadLoader.js:47:3)

但问题不要离开我。

【问题讨论】:

请将标题更改为您的问题 @satanTime 没问题。哪个标题更好看? 这描述了您的问题。目前这听起来像是建议。 @satanTime 标题已更正。谢谢! Node sass 使用原生代码。它应该使用 node-gyp 构建。尝试重新安装它 【参考方案1】:

运行以下命令: rm -rf ./node_modules ./package-lock.json,然后 npm cache verifyPS:我推荐安装nvm

$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

另外我不知道你是否已经安装了它,但请确保也安装了build-essential

$ sudo apt update && apt install build-essential 

它是一组 c++ 编译器和一堆有用的?

我看到的其他情况是缺少 python 2.x.x

$ sudo apt install python

【讨论】:

你做了除了一件事之外的所有事情npm WARN You are using a pre-release version of node and things may not work as expected 还有这个 ``` pm WARN 生命周期 用于脚本的节点二进制文件是 /snap/bin/node 但 npm 正在使用 /snap/node/2725/bin /节点本身。 ``` 是告诉你用来编译node-sass的snap的node版本和当前版本不兼容。这就是为什么我提到 nvm github.com/nvm-sh/nvm 安装 Python 为我修复了 Ubuntu 20.14 上的错误【参考方案2】:

试试这个,它对我有用

npm i --unsafe-perm node-sass

【讨论】:

【参考方案3】:

在 /root/.npm/node-sass/4.14.1/linux-x64-83_binding.node 找到的缓存二进制文件 在 /usr/local/lib/node_modules/node-sass/vendor/linux-x64-83/binding.node 找到的二进制文件 测试二进制

我会说问题可能是因为它使用的是您升级到 Ubuntu 20 之前的缓存版本,在这种情况下,删除缓存的二进制文件可以解决这个问题。

https://docs.npmjs.com/cli-commands/cache.html

这只是我的假设,到目前为止,您尝试过什么来解决此问题?

【讨论】:

我试图清除缓存,尽管系统警告。没有帮助。 npm 卸载 node-sass。之后:npm install node-sass。没有帮助。【参考方案4】:

安装前请检查你的node版本,node-sass对node版本有限制,如下图:

参考https://github.com/sass/node-sass

【讨论】:

以上是关于无法在 Ubuntu 20 上安装“node-sass”的主要内容,如果未能解决你的问题,请参考以下文章

无法在 Ubuntu 20 上安装“node-sass”

无法在 ubuntu 20.04 上通过 apt 安装 curl

SoapUI 5.6.0 无法在 Ubuntu 20.04 LTS 上安装

在 ubuntu 20.04 上全新安装后,无法为 react 项目正确设置 java 1.8

Ubuntu20.04上3090显卡安装Nvidia驱动和CUDA11.4,cuDNN,anaconda,以及解决向日葵无法连接和重装Ubuntu20.04遇到的问题

无法在虚拟机上安装Ubuntu 20.04。