为啥 NPMInstall 不能构建这个 node-sass 依赖?

Posted

技术标签:

【中文标题】为啥 NPMInstall 不能构建这个 node-sass 依赖?【英文标题】:Why can't NPMInstall build this node-sass dependency?为什么 NPMInstall 不能构建这个 node-sass 依赖? 【发布时间】:2021-10-10 13:59:20 【问题描述】:

在尝试运行“npm install”后,我遇到了这个错误,无法继续,甚至无法成功运行我的 gradle 构建。

Unable to save binary C:\path\node_modules\node-sass\vendor\win32-x64-59:  Error: ENOENT: no such file or directory, mkdir 'C:\path\node_modules\node-sass\vendor\win32-x64-59'
    at Object.fs.mkdirSync (fs.js:909:18)
    at checkAndDownloadBinary (C:\path\node_modules\node-sass\scripts\install.js:113:8)
    at Object.<anonymous> (C:\path\node_modules\node-sass\scripts\install.js:156:1)
    at Module._compile (module.js:662:30)
    at Object.Module._extensions..js (module.js:673:10)
    at Module.load (module.js:575:32)
    at tryModuleLoad (module.js:515:12)
    at Function.Module._load (module.js:507:3)
    at Function.Module.runMain (module.js:703:10)
    at startup (bootstrap_node.js:193:16)
  errno: -4058,
  code: 'ENOENT',
  syscall: 'mkdir',
  path: 'C:\path\\node_modules\\node-sass\\vendor\\win32-x64-59' 

我尝试编辑 .npmrc 文件,因为最初报告的错误是尝试从不可用的 url 下载,所以我添加了这一行。

sass_binary_site=https://github.com/sass/node-sass/releases/download/v4.13.1/win32-x64-79_binding.node

我还尝试运行“gradle uberClean”、“npm uninstall node-sass”和“npm install node-sass”,并删除了 node-modules 以重新开始构建。没有任何效果。它还会同时报告python错误,但我不确定它是否相关。

Building: C:\path\.gradle\nodejs_9.6.0\node-v9.6.0-win-x64\node.exe C:\path\node_modules\node-sass\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:\path\\.gradle\\nodejs_9.6.0\\node-v9.6.0-win-x64\\node.exe',
gyp verb cli   'C:\path\\node_modules\\node-sass\\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@7.1.2
gyp info using node@9.6.0 | win32 | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb find Python checking Python explicitly set from command line or npm configuration
gyp verb find Python - "--python=" or "npm config get python" is "C:\Program Files\Python37\python.exe"
gyp verb find Python - executing "C:\Program Files\Python37\python.exe" to get executable path
gyp verb find Python - executable path is "C:\Program Files\Python37\python.exe"
gyp verb find Python - executing "C:\Program Files\Python37\python.exe" to get version
gyp verb find Python - version is "3.7.9"
gyp info find Python using Python version 3.7.9 found at "C:\Program Files\Python37\python.exe"
gyp verb get node dir no --target version specified, falling back to host node version: 9.6.0
gyp verb command install [ '9.6.0' ]
gyp verb install input version string "9.6.0"
gyp verb install installing version: 9.6.0
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version not already installed, continuing with install 9.6.0
gyp verb ensuring nodedir is created C:\Users\bryce.eller\AppData\Local\node-gyp\Cache\9.6.0
gyp WARN install got an error, rolling back install
gyp verb command remove [ '9.6.0' ]
gyp verb remove using node-gyp dir: C:\Users\bryce.eller\AppData\Local\node-gyp\Cache
gyp verb remove removing target version: 9.6.0
gyp verb remove removing development files for version: 9.6.0
gyp ERR! configure error
gyp ERR! stack Error: ENOENT: no such file or directory, mkdir 'C:\Users\bryce.eller\AppData\Local\node-gyp\Cache\9.6.0'gyp ERR! System Windows_NT 10.0.18363
gyp ERR! command "C:\path\\.gradle\\nodejs_9.6.0\\node-v9.6.0-win-x64\\node.exe" "C:\path\\node_modules\\node-sass\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd C:\path\node_modules\node-sass
gyp ERR! node -v v9.6.0
gyp ERR! node-gyp -v v7.1.2
gyp ERR! not ok
Build failed with error code: 1
npm WARN leaflet.markercluster@1.4.1 requires a peer of leaflet@~1.3.1 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules\watchpack\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted "os":"darwin","arch":"any" (current: "os":"win32","arch":"x64")
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted "os":"darwin","arch":"any" (current: "os":"win32","arch":"x64")

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@6.0.1 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@6.0.1 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!    C:\path\npm-cache\_logs\2021-08-05T14_12_09_736Z-debug.log

任何关于如何让我的构建再次成功运行的提示都很棒!提前致谢!

【问题讨论】:

【参考方案1】:

Node 9 于 2018 年 6 月终止使用。我建议至少迁移到 Node 12 的当前 LTS 版本。该版本的 node-sass https://github.com/sass/node-sass#node-version-support-policy 支持这一点

【讨论】:

【参考方案2】:

很多事情都可能导致这种情况。我认为最常见的是 NVM。使用它来切换版本和缓存可能会搞砸。建议。

    切换到纯JS版本的Saas:https://www.npmjs.com/package/sass 清除缓存目录:C:\Users\bryce.eller\AppData\Local\node-gyp\Cache 如果尚未进行初始安装,请删除 node_modules 并从头开始安装 升级版node-sass

node-sass 因编译错误而臭名昭著;在本地和 CI 服务器上。如果您可以控制项目,我强烈建议您切换到纯 JS 版本。

【讨论】:

1:不幸的是,我对这个项目没有太多的控制权,所以切换是不可能的。 2:我的 AppData 文件夹中没有 node-gyp 文件夹,我的机器周围散落着一些其他文件夹,但没有一个缓存文件夹,这可能与这个问题有关吗? 3:尝试失败 4:package.json 设置为使用 6.0.1,我认为这是最新版本 @BryceEller OIC,安装尝试创建该目录时出现错误。确保此目录完全存在:C:\Users\bryce.eller\AppData\Local\node-gyp

以上是关于为啥 NPMInstall 不能构建这个 node-sass 依赖?的主要内容,如果未能解决你的问题,请参考以下文章

为啥“npm install”在我的“package-lock.json”文件中为我的包添加“node_modules”前缀?

为啥 NPM 安装安装旧版本的 node-sass

为啥我不能在 docker 中构建这个 nuxtjs 应用程序,而本地构建工作?

为啥在 `npm install` 时`package-lock.json` 会导致 docker 容器构建失败?

node升级后npm install不能安装新版本

vue构建项目步骤