错误1:
error Error: getaddrinfo ENOTFOUND registry.nlark.com at GetAddrInfoReqWrap.
解决1:
修改yarn.lock文件里registry.nlark.com 改为 registry.npmmirror.com
错误2:
gyp verb check python checking for Python executable "python2" in the PATH g
解决2:
这个错误信息是由node-gyp在尝试找到Python 2.x版本时产生的,因为node-gyp需要Python 2.x来构建一些本地的C++扩展。
首先需要安装Python 2.x版本,配置环境变量。
接着执行:
mklink /H D:\Python27\python2.exe D:\Python27\python.exe
将python映射为python2
错误3:
gyp ERR! stack Error: spawn D:\Microsoft Visual Studio\MSBuild\15.0\Bin\MSBuild.exe
解决3:
重新设置MSBuild编译器版本和路径
比如我的:
npm config set msbuild_path “D:\Microsoft Visual Studio\MSBuild\Current\Bin\MSBuild.exe”
错误4:
gyp ERR! UNCAUGHT EXCEPTION
gyp ERR! stack Error: spawn D:\Microsoft ENOENT
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:277:19)
gyp ERR! stack at onErrorNT (internal/child_process.js:472:16)
gyp ERR! System Windows_NT 10.0.19045
gyp ERR! command "D:\\Node.js\\node.exe" "D:\\hytCode\\20240505\\console\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd D:\hytCode\20240505\console\node_modules\node-sass
gyp ERR! node-gyp -v v3.8.0
gyp ERR! This is a bug in `node-gyp`.
即使改了编译器版本和路径,它还是找不到指定的路径或文件。
具体来说,错误信息显示 spawn D:\Microsoft ENOENT
,这意味着系统尝试在 D:\Microsoft
目录中找到 MSBuild
,但没有成功。
解决4:
手动指定 msbuild_path
: 如果设置环境变量后仍然有问题,你可以在构建命令中手动指定 msbuild_path
。
在你的项目目录中创建或编辑 .npmrc
文件
你可以通过这样找到:按住 win+E
,输入:%USERPROFILE%
可以找到.npmrc文件
添加如下内容
可以看到文件内容:
sharp_binary_host=https://npmmirror.com/mirrors/sharp
sharp_libvips_binary_host=https://npmmirror.com/mirrors/sharp-libvips
msbuild_path=D:\Microsoft
可以看到msbuild_path的路径为报错的路径
将msbuild_path改为:
msbuild_path=D:\Microsoft Visual Studio\MSBuild\Current\Bin\MSBuild.exe
点击保存,重新编译即可。