当前位置:

npm install 提示 path xxx/node_modules/node-sass npm ERR command failed 解决方法

本文最后更新于2022-06-14,已超过 1年没有更新,如果文章内容、图片或者下载资源失效,请留言反馈,我会及时处理,谢谢!

温馨提示:本文共2465个字,读完预计7分钟。

文章目录
  • 起因
    前后经历了多次无法进行 npm install,每次安装依赖都出现类似于 path xxx/node_modules/node-sass npm ERR! command failed 的报错。就因为数次遇到这种错,导致对前端的技术栈有点烦躁,虽然如此,但工作需要,还是要耐心去维护。
  • 自己解决过程:
     遇到错误一:
    [1/2] scripts.install node-sass@^4.5.2 run "node scripts/install.js", root: "E:\\MyHtmlProcess\\online-store\\node_modules\\_node-sass@4.14.1@node-sass"
    Downloading binary from https://cdn.npmmirror.com/binaries/node-sass/v4.14.1/win32-x64-93_binding.node
    ***Cannot download "https://cdn.npmmirror.com/binaries/node-sass/v4.14.1/win32-x64-93_binding.node":***
  • 解决方法:
  • 一开始直接去下载93版本的node-sass, 放到安全目录,npm config set SASS_BINARY_PATH=D:\nodejs\win32-x64-93_binding.node, 然后执行 npm install
 

起因
前后经历了多次无法进行 npm install,每次安装依赖都出现类似于 path xxx/node_modules/node-sass npm ERR! command failed 的报错。就因为数次遇到这种错,导致对前端的技术栈有点烦躁,虽然如此,但工作需要,还是要耐心去维护。

自己解决过程:
 遇到错误一:
[1/2] scripts.install node-sass@^4.5.2 run "node scripts/install.js", root: "E:\\MyHtmlProcess\\online-store\\node_modules\\_node-sass@4.14.1@node-sass"
Downloading binary from https://cdn.npmmirror.com/binaries/node-sass/v4.14.1/win32-x64-93_binding.node
***Cannot download "https://cdn.npmmirror.com/binaries/node-sass/v4.14.1/win32-x64-93_binding.node":***

***HTTP error 404 Not Found***

Hint: If github.com is not accessible in your location
      try setting a proxy via HTTP_PROXY, e.g.
gyp verb command configure []
gyp verb download using dist-url https://npmmirror.com/mirrors/node
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2
gyp verb `which` failed     at getNotFoundError (E:\MyHtmlProcess\online-store\node_modules\_which@1.3.1@which\which.js:13:12)


注意上面用粗体标注的 :意思是下载node-sass/v4.14.1/win32-x64-93_binding.node
第一个是版本,第二个是 404 没有找到。可能是网络的问题吧,
这个可以到官方网站下载:
可以去GitHub找到node-sass的对应版本:

https://github.com/sass/node-sass/releases
node-sass版本,GitHub
PS:(
    一开始报错提示的是无法找到 python2.7 建议设置 PYTHON 环境变量,我特意去安装了一个python2 然后设置环境变量,但却无法解决问题。
第一次我没有注意node-sass 的版本,然后直接就下载了一个win32-x64-102_binding.node, 放到一个目录下,然后设置指定的目录:
set SASS_BINARY_PATH=E:\NodeJs\win32-x64-102_binding.node,在执行 npm install
接着下面一个报错。

遇到错误二:
Binary found at E:\NodeJs\win32-x64-102_binding.node
Testing binary
Binary has a problem: Error: The module '\\?\E:\NodeJs\win32-x64-102_binding.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 102. This version of Node.js requires
NODE_MODULE_VERSION 93. Please try re-compiling or re-installing
…….此处内容过长
Building the binary locally
Building: E:\NodeJs\node.exe E:\MyHtmlProcess\online-store\node_modules\_node-gyp@3.8.0@node-gyp\bin\node-gyp.js rebuild –verbose –libsass_ext= –libsass_cflags= —
gyp verb download using dist-url https://npmmirror.com/mirrors/node
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2
PS: 这个时候我有重新阅读了一下报的日志信息,意思是我安装的版本不对,让我重新安装93的,我下载的版本问题。同样上面的操作:set SASS_BINARY_PATH=E:\NodeJs\win32-x64-93_binding.node,在执行 npm install

解决方法:

一开始直接去下载93版本的node-sass, 放到安全目录,npm config set SASS_BINARY_PATH=D:\nodejs\win32-x64-93_binding.node, 然后执行 npm install

问题解决。一开始下载404 支援没有找到,我用淘宝镜像安装 cnpm 安装的没有成功。
解决问题的时候,还是注意看根本的报错原因,然后再去操作,不然会走弯路。


————————————————
版权声明:本文为CSDN博主「晨伊」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_43372749/article/details/123029518
本文链接:,转发请注明来源!
评论已关闭。