当我尝试在我的本地安装vue商店前,但当我尝试“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

当前回答

当我使用比当前支持的Node -sass(4.9)版本更新的Node (16 via nvm)时,我遇到了这个问题。回到节点10可以缓解这个问题。Ângelo Polotto的答案有一个很好的兼容性图表。

其他回答

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

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

Had a similar problem with /node_modules/node-sass: Command failed on building my application, which also occurred within the last week without any updates on my end. Had a look at the node-sass docs and the node version on the server and it was using node v12.13.0 and the version of node-sass was 4.9.x. in the node-sass release docs it lists that for node v12 you need to have node-sass v4.12 and up. Updating node-sass version corrected the build for me, hope it helps for you too. node Release docs: https://github.com/sass/node-sass/releases

针对Rails用户

对我来说,这很容易解决。如果您正在使用nvm,只需确保您安装了正确的节点版本并正在使用。

步骤:

检查节点版本号 如果节点版本与您的rails项目使用的版本不同,则更新(例如使用节点16,但项目使用节点14),执行nvm use 14 走纱安装

这应该有用。

尝试安装sass而不是node-sass。这对我来说很有效。

yarn remove node-sass
yarn add sass

通过run来检测当前NPM配置的python路径: $ NPM配置python

如果它不是你当前的python路径,那么通过run改变它: $ npm config set python=<YOUR_PYTHON_DIR_PATH>

(例如,在我的机器中,它是:C:\python311)

我也遇到过同样的问题,我用以下步骤解决了这个问题:

如果你使用的是苹果M1芯片,使用Rosetta 2运行终端(可选,只有在你安装了Rosetta的节点时才有必要) 检查包中的node-sass版本。并与下表进行比较:

NodeJS Supported node-sass version Node Module
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——version检查节点版本 根据你的node-sass安装Nodejs版本,如果你使用NVM,执行命令NVM use DESIRED_VERSION 清理旧的node_modules文件夹,删除或在终端上键入:rm -rf node_modules 运行:NPM install

资源:

https://www.npmjs.com/package/node-sass