错误 /node_modules/node-sass: 命令失败

Adi*_*dil 64 node.js vue.js yarnpkg

当我尝试在本地安装 vue store front 但当我尝试“yarn install”命令时,出现以下错误。我该如何解决这个错误?我该如何解决这个错误?

error /var/www/html/vue-storefront/node_modules/node-sass: Command failed.
Exit code: 1
Command: node scripts/build.js
Arguments: 
Directory: /var/www/html/vue-storefront/node_modules/node-sass
Output:
Building: /usr/bin/node /var/www/html/vue-storefront/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli   '/usr/bin/node',
gyp verb cli   '/var/www/html/vue-storefront/node_modules/node-gyp/bin/node-gyp.js',
gyp verb cli   'rebuild',
gyp verb cli   '--verbose',
gyp verb cli   '--libsass_ext=',
gyp verb cli   '--libsass_cflags=',
gyp verb cli   '--libsass_ldflags=',
gyp verb cli   '--libsass_library='
gyp verb cli ]
gyp info using node-gyp@3.8.0
gyp info using node@13.9.0 | linux | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "/usr/bin/python3.6" in the PATH
gyp verb `which` succeeded /usr/bin/python3.6 /usr/bin/python3.6
gyp ERR! configure error 
gyp ERR! stack Error: Command failed: /usr/bin/python3.6 -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack   File "<string>", line 1
gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack                                ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack 
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:303:12)
gyp ERR! stack     at ChildProcess.emit (events.js:321:20)
gyp ERR! stack     at maybeClose (internal/child_process.js:1026:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
gyp ERR! System Linux 4.15.0-88-generic
gyp ERR! command "/usr/bin/node" "/var/www/html/vue-storefront/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /var/www/html/vue-storefront/node_modules/node-sass
gyp ERR! node -v v13.9.0
Run Code Online (Sandbox Code Playgroud)

小智 86

我遇到了同样的问题,将 node-sass 版本升级为与 node 版本相同。用纱线运行:

yarn add node-sass
Run Code Online (Sandbox Code Playgroud)

这将升级版本并解决问题

  • 不工作。得到“Node.js Sass 版本 7.0.0 与 ^4.0.0 不兼容”。需要做:`yarn remove node-sass`、`yarn add sass`。 (7认同)

Âng*_*tto 39

我遇到了同样的问题,我通过以下步骤解决了:

  1. 如果您使用的是 Apple M1 芯片,请运行终端Rosetta 2(可选,仅当您安装了 Rosetta 的节点时才需要)
  2. 检查您的node-sass版本package.json并与下表进行比较:
节点 支持的 node-sass 版本 节点模块
节点 16 6.0+ 93
节点 15 5.0+ 88
节点 14 4.14+ 83
节点 13 4.13+,<5.0 79
节点 12 4.12+ 72
节点 11 4.10+,<5.0 67
节点 10 4.9+,<6.0 64
节点 8 4.5.3+,<5.0 57
节点 <8 <5.0 <57
  1. 根据你的安装 Nodejs 版本 node-sass
  2. 使用以下命令清理旧的 node_modules: rm -rf node_modules
  3. 跑: npm install

资源:

  • 谢谢!这是一个很好的暗示。我不得不降级我的节点版本并且它起作用了。 (4认同)
  • 我正在运行 Angular 并将 package.json 中的 node-sass 更新为 6.0.1 以匹配我的节点 16 ...... (2认同)

tro*_*rta 27

如果它是一个 Rails 项目,升级 webpacker 就可以帮我完成这项工作。

yarn add @rails/webpacker
Run Code Online (Sandbox Code Playgroud)


mar*_*ion 18

我正在跑步Rails 6,出于某种原因,它正在拉动webpacker 4.3.0哪个正在拉动,node-sass 4.3.0而不是6.0.0截至本文发布之日最新的那个。

对我有用的是以下内容:

  1. 删除node_module文件夹,package-lock.json以及yarn.lock
  2. 在我的package.json,我升级了rails/webpacker: 5.3.0
  3. 然后我重新跑了yarn install
  4. 然后我跑了 yarn add node-sass

在尝试了上述所有其他方法之后,这就像一种魅力。

我相信这些是确切的步骤,虽然老实说我一直在尝试很多东西,但它们没有奏效,我终于让它起作用了,所以我可能错过了一步,但我尽力了为任何未来受挫的灵魂重新创造它。

  • 第 4 步在我的情况下不是必需的 (10认同)
  • 我所做的就是第 2 步,然后运行一个“yarn”,这对我有用。 (3认同)
  • 简单地执行步骤 #2 和 #3 对我来说很有效。谢谢! (2认同)

小智 15

我在 package.json 文件中将节点版本从 16.0 更改为 14.x,并且它有效。


小智 13

只需在您的文件中升级您的sass版本yarn.lock。对于节点 14,适当的版本node-sass4.14
所以适应你的节点版本。


小智 10

这里的解决方案对我不起作用。直到我删除node_modules文件夹和yarn.lock。

rm -rf node_modules
rm yarn.lock
yarn instal
Run Code Online (Sandbox Code Playgroud)


小智 7

这里有同样的问题。我做到了

nvm install 14  
Run Code Online (Sandbox Code Playgroud)

因为node-sass我的版本是package.json然后4.14.1 这将显示 - 现在使用node v14.19.3( npm v6.14.17) 在我这样做之后

yarn install
Run Code Online (Sandbox Code Playgroud)

这是成功的


小智 6

尝试安装 sass 而不是 node-sass。它对我有用。

yarn remove node-sass
yarn add sass
Run Code Online (Sandbox Code Playgroud)


小智 6

我在 Rails 应用程序上遇到同样的问题已经有一段时间了,并通过升级 webpacker 解决了:

# check your Gemfile for version restrictions
bundle update webpacker

# overwrite your changes to the default install files and revert any unwanted changes from the install
rails webpacker:install

# yarn 1 instructions
yarn upgrade @rails/webpacker --latest
yarn upgrade webpack-dev-server --latest
Run Code Online (Sandbox Code Playgroud)

请参阅: https: //github.com/rails/webpacker#upgrading

chase439 的道具:https ://github.com/sass/node-sass/issues/2447


use*_*295 6

对于我来说,升级到最新的v7.0.1后问题就解决了。基于这个github问题,node-sass团队已在7.0及以上版本中修复了该问题。

我正在使用 Node v16.13.2 和 Apple M1 芯片。


sau*_*aud 5

面临同样的问题。如果您查看错误堆栈,它会说:

Error: Command failed: /usr/bin/python3.6 -c import sys; print "%s.%s.%s" % sys.version_info[:3];
   File "<string>", line 1
     import sys; print "%s.%s.%s" % sys.version_info[:3];
                                ^
 SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

它试图使用 Python2,但使用不受支持的 Python3。

我的系统在使用python命令调用时运行 Python3 ,因此我通过安装 Python2 并将其别名为python命令来解决此问题:

Error: Command failed: /usr/bin/python3.6 -c import sys; print "%s.%s.%s" % sys.version_info[:3];
   File "<string>", line 1
     import sys; print "%s.%s.%s" % sys.version_info[:3];
                                ^
 SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)


Vik*_*iev 5

我的解决方案使用节点 v10.19.0

https://github.com/nodejs/docker-node/issues/1149#issuecomment-552705885

/node_modules/node-sass 也有类似的问题:构建我的应用程序时命令失败,这也发生在上周,而我这边没有任何更新。

查看了node-sass文档和服务器上的node版本,它使用的是node v12.13.0,node-sass的版本是4.9.x。

在node-sass发行文档中,它列出了对于node v12,您需要有node-sass v4.12及更高版本。

更新node-sass版本为我纠正了构建,希望它对你也有帮助。

节点发布文档: https: //github.com/sass/node-sass/releases


小智 3

node-sass全局安装yarn

或者添加node-sass到您的项目中