📜  在 node-sass@4.10.0 安装后脚本失败. - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:37:24.884000             🧑  作者: Mango

在 node-sass@4.10.0 安装后脚本失败

当你尝试在你的项目中安装node-sass包时,可能会遇到以下错误:

gyp ERR! find VS 
gyp ERR! find VS msvs_version not set from command line or npm config
gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer because PowerShell is not available on this machine

这个问题通常是因为当前计算机上缺少Visual Studio的某些组件导致的。这个问题有几个解决方法:

安装Visual Studio

第一个解决办法是安装适合当前计算机的Visual Studio版本,这可能是 download.microsoft.com 或者是商店应用中下载的某个版本。这个解决办法可能比较耗时,但通常是解决node-sass安装问题的最佳方法。

配置环境变量或使用命令行

第二个方法是在命令行中配置一些变量来解决问题。我们将需要设置npm_config_node_gypnpm_config_node_gyp环境变量,以使用合适的安装目录和工具链。

npm install --global --production windows-build-tools
set PYTHON=C:\Python27\python.exe
npm config set msvs_version 2017 --global

如果你正在使用PowerShell,你需要在管理员模式下运行PowerShell,以便设置相关策略。

以上是一些常见的解决node-sass安装问题的方法,但并不一定适用于所有情况。如果您仍然遇到问题,请到官方的issue页面查看更多解决方案。