node-sass安装失败 error D:\xxx\xxx\node_modules\node-sass: Command failed.

本文转载于:https://www.baidu.com/link?url=tRpRIa3I200I2lXN18suAsq_kCZj7YXY6IAQc0eq2y5okHgIuHwJ0eZ62Ayi2cZLOwm9uiS9fYZozex-MvKq1a&wd=&eqid=b1d98b380003c0c7000000066191dda5

error D:\xxx\xxx\node_modules\node-sass: Command failed.
导言:运行老项目的时候经常遇到node-sass安装不下来的问题,百度搜索更是千篇一律的镜像原因,当然镜像问题原因是更多人可能遇到的问题,比较少见的一种是运行老项目时,node版本比较低,导致node-sass安装不了

提示node-sass安装异常我遇到过两种情况,一种是安装依赖时需要node-sass,报错一般是↓↓↓

error D:\xxx\xxx\node_modules\node-sass: Command failed.
Exit code: 1
Command: node scripts/build.js
Arguments:
Directory: D:\xxx\xxx\node_modules\node-sass
Output:
Binary found at D:\software\nodesass\win32-x64-72_binding.node
Testing binary
Binary has a problem: Error: The module '\\?\D:\software\nodesass\win32-x64-72_binding.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 64. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:717:18)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at module.exports (D:\xxx\xxx\node_modules\node-sass\lib\binding.js:19:10)
    at Object.<anonymous> (D:\xxx\xxx\node_modules\node-sass\lib\index.js:14:35)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
Building the binary locally
Building: C:\Program Files\nodejs\node.exe D:\xxx\xxx\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 [ 'C:\\Program Files\\nodejs\\node.exe',
gyp verb cli   'D:\\xxx\\xxx\\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 info using node-gyp@3.8.0
gyp info using node@10.14.1 | win32 | 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 "python2" in the PATH
gyp verb `which` failed Error: not found: python2
gyp verb `which` failed     at getNotFoundError (D:\xxx\xxx\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (D:\xxx\xxx\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (D:\xxx\xxx\node_modules\which\which.js:80:29)
gyp verb `which` failed     at D:\xxx\xxx\node_modules\which\which.js:89:16
gyp verb `which` failed     at D:\xxx\xxx\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at D:\xxx\xxx\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:154:21)
gyp verb `which` failed  python2 { Error: not found: python2
gyp verb `which` failed     at getNotFoundError (D:\xxx\xxx\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (D:\xxx\xxx\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (D:\xxx\xxx\node_modules\which\which.js:80:29)
gyp verb `which` failed     at D:\xxx\xxx\node_modules\which\which.js:89:16
gyp verb `which` failed     at D:\xxx\xxx\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at D:\xxx\xxx\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:154:21)
gyp verb `which` failed   stack:
gyp verb `which` failed    'Error: not found: python2\n    at getNotFoundError (D:\\xxx\\xxx\\node_modules\\which\\which.js:13:12)\n    at F (D:\\xxx\\xxx\\node_modules\\which\\which.js:68:19)\n    at E (D:\\xxx\\xxx\\node_modules\\which\\which.js:80:29)\n    at D:\\xxx\\xxx\\node_modules\\which\\which.js:89:16\n    at D:\\xxx\\xxx\\node_modules\\isexe\\index.js:42:5\n    at D:\\xxx\\xxx\\node_modules\\isexe\\windows.js:36:5\n    at FSReqWrap.oncomplete (fs.js:154:21)',
gyp verb `which` failed   code: 'ENOENT' }
gyp verb check python checking for Python executable "python" in the PATH
gyp verb `which` failed Error: not found: python
gyp verb `which` failed     at getNotFoundError (D:\xxx\xxx\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (D:\xxx\xxx\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (D:\xxx\xxx\node_modules\which\which.js:80:29)
gyp verb `which` failed     at D:\xxx\xxx\node_modules\which\which.js:89:16
gyp verb `which` failed     at D:\xxx\xxx\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at D:\xxx\xxx\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:154:21)
gyp verb `which` failed  python { Error: not found: python
gyp verb `which` failed     at getNotFoundError (D:\xxx\xxx\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (D:\xxx\xxx\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (D:\xxx\xxx\node_modules\which\which.js:80:29)
gyp verb `which` failed     at D:\xxx\xxx\node_modules\which\which.js:89:16
gyp verb `which` failed     at D:\xxx\xxx\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at D:\xxx\xxx\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:154:21)
gyp verb `which` failed   stack:
gyp verb `which` failed    'Error: not found: python\n    at getNotFoundError (D:\\xxx\\xxx\\node_modules\\which\\which.js:13:12)\n    at F (D:\\xxx\\xxx\\node_modules\\which\\which.js:68:19)\n    at E (D:\\xxx\\xxx\\node_modules\\which\\which.js:80:29)\n    at D:\\xxx\\xxx\\node_modules\\which\\which.js:89:16\n    at D:\\xxx\\xxx\\node_modules\\isexe\\index.js:42:5\n    at D:\\xxx\\xxx\\node_modules\\isexe\\windows.js:36:5\n    at FSReqWrap.oncomplete (fs.js:154:21)',
gyp verb `which` failed   code: 'ENOENT' }
gyp verb could not find "python". checking python launcher
gyp verb could not find "python". guessing location
gyp verb ensuring that file exists: C:\Python27\python.exe
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack     at PythonFinder.failNoPython (D:\xxx\xxx\node_modules\node-gyp\lib\configure.js:484:19)
gyp ERR! stack     at PythonFinder.<anonymous> (D:\xxx\xxx\node_modules\node-gyp\lib\configure.js:509:16)
gyp ERR! stack     at D:\xxx\xxx\node_modules\graceful-fs\polyfills.js:284:29
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:154:21)
gyp ERR! System Windows_NT 10.0.19042
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "D:\\xxx\\xxx\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd D:\xxx\xxx\node_modules\node-sass
gyp ERR! node -v v10.14.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

一种是依赖安装成功,但跑项目时因为部分依赖依赖了node-sass导致运行不成功,异常一般是↓↓↓

internal/modules/cjs/loader.js:717
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: The module '\\?\D:\nodesass\win32-x64-72_binding.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 64. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:717:18)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at module.exports (D:\xxx\xxx\node_modules\node-sass\lib\binding.js:19:10)
    at Object.<anonymous> (D:\xxx\xxx\node_modules\node-sass\lib\index.js:14:35)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

出现这种情况一般都是node-sass版本和node版本不对应,拿以上错误举例

This version of Node.js requires NODE_MODULE_VERSION 64.

这句话的意思是:此版本的Node.js需要使用64版本的node-sass

可以去GitHub找到node-sass的对应版本:

https://github.com/sass/node-sass/releases
比如说我当前使用的node版本是10.14.1,则找到对应系统的对应node版本
在这里插入图片描述
下载对应系统对应node版本所需的node-sass
在这里插入图片描述
下载后放到本地磁盘,比如D盘

如果是安装依赖时出了错,则建议先把之前安装的node_modules删掉,然后设置node-sass路径↓↓↓

// 删除node_modules建议用命令行,更快!!
rmdir /s node_modules
// set SASS_BINARY_PATH=node-sass所在的路径
set SASS_BINARY_PATH=D:/nodesass/win32-x64-64_binding.node

设置好node-sass路径好正常安装依赖即可

npm i 或 yarn

如果安装依赖成功,但运行时出了node-sass的错,则直接设置node-sass路径然后运行↓↓↓

// set SASS_BINARY_PATH=node-sass所在的路径
set SASS_BINARY_PATH=D:/nodesass/win32-x64-64_binding.node
npm run dev 或 yarn dev

注意:如果你通过以上方法成功安装了依赖并成功运行了,但是,你在同时维护几个不同node版本的项目,需要切换不同版本的node-sass和node,则建议切换项目后再设置一下node-sass路径。
end~

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: error d:\lanqin-pro\avue-master\node_modules\node-sass: command failed. exit。 这个错误提示表明在指定的路径下的`node_modules`文件夹中的`node-sass`模块命令执行失败并导致退出。 出现这个错误的原因可能有以下几种情况: 1. 缺少依赖:`node-sass`模块是一个依赖于Node.js的Sass解析器,它需要依赖于相关的Node.js环境,如果没有正确安装相关依赖,就会导致命令执行失败。解决办法是检查是否已正确安装Node.js以及相关依赖,并更新到最新版本。 2. 网络问题:有时候网络连接不稳定或无法访问相关资源,也可能导致`node-sass`的命令执行失败。解决办法是检查网络连接状态,确保可以正常访问相关资源。 3. 文件损坏:`node-sass`模块的文件可能损坏或缺失。解决办法是删除`node_modules`文件夹,并重新执行`npm install`命令来重新安装依赖。 4. 权限问题:在某些情况下,可能没有权限访问或执行相关命令。解决办法是以管理员身份运行命令提示符或终端,并确保具有执行相关命令的权限。 综上所述,错误提示`error d:\lanqin-pro\avue-master\node_modules\node-sass: command failed. exit。`可能是由缺少依赖、网络问题、文件损坏或权限问题引起的。根据具体情况,可以通过安装依赖、检查网络连接、删除重新安装依赖或以管理员身份运行命令来解决该问题。 ### 回答2: 错误d:\lanqin-pro\avue-master\node_modules\node-sass:命令执行失败,退出。 这个错误通常发生在使用Node.js项目中使用的node-sass模块。它通常是由于编译或安装错误引起的。 有几个可能的原因和解决方法可以尝试: 1. 缺少依赖项:首先,确保你的项目中已经安装了所有必需的依赖项。可以使用命令`npm install`或`yarn install`来安装项目所需的所有模块和依赖项。 2. 编译问题:如果编译失败,可能是由于缺少编译所需的C/C++构建工具或组件。你可以尝试使用命令`npm rebuild node-sass`来重新构建node-sass模块。 3. 网络问题:有时,由于网络问题,无法从npm注册表下载所需的模块。你可以尝试更改npm镜像源或使用代理服务器来解决这个问题。 4. 版本冲突:如果你的项目中使用了多个版本的node-sass模块,可能会导致冲突。尝试将所有版本更新到最新,并确保它们与项目的其他部分兼容。 5. 操作系统兼容性:某些node-sass模块可能不兼容你所使用的操作系统。在这种情况下,你可以尝试使用不同版本的node-sass模块,或者转向其他替代方案。 如果以上方法都没有解决问题,建议查看错误日志以获得更详细的错误信息。这将有助于诊断和解决问题。 ### 回答3: 根据提供的信息,错误是由于在路径d:\lanqin-pro\avue-master\node_modules\node-sass下执行的命令失败所致,导致退出。 这个错误通常是由于缺少依赖或配置问题引起的。为了解决这个问题,你可以尝试以下几种方法: 1. 检查依赖项:运行npm install命令,确认所有依赖项都已成功安装。如果有任何依赖项安装失败或丢失,可以尝试手动安装它们。 2. 清除缓存:运行npm cache clean命令清除npm缓存,然后再次尝试安装依赖项。 3. 更新node-sass:运行npm update node-sass命令将node-sass更新到最新版本。有时,旧版本的node-sass可能与其他依赖项不兼容,导致失败。 4. 检查环境变量:确保PATH环境变量中包含了正确的Node.js和npm安装路径。有时,错误可能是由于环境变量配置不正确导致的。 5. 重新安装Node.js和npm:如果以上方法都不起作用,可以尝试重新安装最新版本的Node.js和npm。 希望以上方法能帮助你解决这个错误。如果还有问题,请提供更多详细信息,以便我们能更好地帮助你解决问题。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值