node-sass,command failed 踩坑记录

记录一个经常踩的坑 node-sass

解决方法:
每次遇到新项目 npm install 后 最容易出的问题就是node-sass,导致node-sass出错一般都是版本问题(至少我每次都是)

卸载

npm uninstall --save-dev sass-loader
npm uninstall node-sass

安装
14版本node

npm install --save-dev sass-loader@7.1.0
npm install node-sass@4.14.1

16版本以后的node不需要 node-sass
直接安装 sass 和 sass-loader

npm i sass
npm i sass-loader

less 踩坑 也是版本问题 (14版本node)

npm install less@3.9.0 --save-dev --force
npm install less-loader@5.0.0 --save-dev --force
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
【用于解决 failed Error: not found: python2 node-sass】 报错信息如下: ``` npm WARN prefer global [email protected] should be installed with -g > node-sass@4.5.2 install E:\workspace_vscode\ww\node_modules\node-sass > node scripts/install.js Downloading binary from https://github.com/sass/node-sass/releases/download/v4.5 .2/win32-x64-48_binding.node Cannot download "https://github.com/sass/node-sass/releases/download/v4.5.2/win3 2-x64-48_binding.node": connect ETIMEDOUT 54.231.72.83:443 Timed out whilst downloading the prebuilt binary Hint: If github.com is not accessible in your location try setting a proxy via HTTP_PROXY, e.g. export HTTP_PROXY=http://example.com:1234 or configure npm proxy via npm config set proxy http://example.com:8080 > node-sass@4.5.2 postinstall E:\workspace_vscode\ww\node_modules\node-sass > node scripts/build.js 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 ``` 这个问题有两个解决方案 1. 按照提示需要 python2 环境,安装python2环境确实可以解决, 网上好多这种(管理员身份执行)。但是当你本来就有python环境时,环境变量不能自动替换,整起来就很麻烦。 ``` npm install --global --production windows-build-tools ``` 2. 第二种解决方案 ,看另一句报错,资源被墙。 ``` Downloading binary from https://github.com/sass/node-sass/releases/download/v4.5.2/win32-x64-48_binding.node Cannot download "https://github.com/sass/node-sass/releases/download/v4.5.2/win32-x64-48_binding.node": ``` 下载此资源即可。下载后需要设置变量路径,防止它再次去下载。 可以设置环境变量 直接右键我的电脑--》属性--》高级系统设置--》环境变量--》添加 或者执行 ``` set SASS_BINARY_PATH=D:\nodejs\tools\node-sass\win32-x64-46_binding.node ``` 再次执行 npm install 成功
根据引用的描述,当使用npm install命令时,出现了"npm ERR! code 1"和"npm ERR! path D:\....\node-sass"的错误信息。同时,引用提供了一种解决方法,即安装指定版本的node-sass。此外,引用也提到了卸载node-sass后,package.json中的node-sass会被删除,可以通过备份恢复package.json文件。 针对"npm ERR! command failed"这个错误信息,可能的原因之一是node-sass安装失败或无法正确运行的问题。为了解决这个问题,可以尝试以下几个方法: 1. 确保你已经安装了最新版本的Node.js。可以通过命令行运行"node -v"来检查当前安装的Node.js版本。如果版本过旧,可以考虑升级到最新版本。 2. 检查你的网络连接是否正常。有时候安装过程中会需要下载依赖包,如果网络不稳定或者被墙,可以尝试使用代理或切换网络环境。 3. 清除npm缓存。你可以通过运行"npm cache clean --force"清除npm的缓存,然后再次尝试安装node-sass。 4. 卸载并重新安装node-sass。根据引用的提示,可以尝试使用指定版本的node-sass进行安装。通过运行"npm uninstall node-sass"卸载当前的node-sass,然后使用"npm install node-sass@指定的版本号"安装特定版本的node-sass。 5. 恢复package.json文件。如果在卸载node-sass后,发现package.json中的node-sass被删除了,可以通过之前备份的package.json文件来恢复。将备份文件重命名为package.json,然后重新运行npm install命令。 请注意,这些方法并不一定适用于所有情况,具体解决方案可能因个人情况而异。如果问题仍然存在,可以尝试查看其他相关错误信息,查找更多解决方法,或者在相关社区或论坛上寻求帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值