一站式解决Node项目中遇到的 诸如sharp Command failed.或Building fresh packages...始终执行问题

一站式解决Node项目中遇到的 诸如sharp: Command failed.或Building fresh packages...始终执行问题

1.问题的形式

形式一:

Building fresh packages...

1. [-/5] ⠐ waiting...
2. [-/5] ⠐ waiting...
3. [3/5] ⠐ electron

形式二:

error /mnt/e/One life projects/OneLifeAdmin/node_modules/favicons/node_modules/sharp: Command failed.
Exit code: 1
Command: (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)
Arguments:
Directory: /mnt/e/One life projects/OneLifeAdmin/node_modules/favicons/node_modules/sharp

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

2. 问题原因

node无法下载相应的module,比如electron或者sharp

一方面和版本有关系,另一方面和网络有关系

所以针对这两方面的问题,有如下的解决方案

3. 方案

  1. 在项目目录下配置.yarnrc(或者.npmrc文件)——最稳定最靠谱

​ 常见的配置:

registry "https://registry.npm.taobao.org"
sass_binary_site "https://npm.taobao.org/mirrors/node-sass/"
phantomjs_cdnurl "http://cnpmjs.org/downloads"
electron_mirror "https://npm.taobao.org/mirrors/electron/"
sqlite3_binary_host_mirror "https://foxgis.oss-cn-shanghai.aliyuncs.com/"
profiler_binary_host_mirror "https://npm.taobao.org/mirrors/node-inspector/"
chromedriver_cdnurl "https://cdn.npm.taobao.org/dist/chromedriver"
sharp_binary_host "https://npm.taobao.org/mirrors/sharp"
sharp_libvips_binary_host "https://npm.taobao.org/mirrors/sharp-libvips"

我找到的配置没有sharp,实际上我遇到这个就是sharp安装不上,然后找到了sharp的国内源,配置过去之后就解决了问题;

  1. 更改版本,这个就看node版本和module版本的适配性了,有什么问题搜什么问题。

​ 参考这篇博文,更改了模块版本https://blog.csdn.net/reality_fei/article/details/105814928

  1. 手动下载对应的module

    参考这篇博文,我尝试了一下没有成功。http://www.javashuo.com/article/p-ajfihdjb-cv.html

posted @ 2022-11-14 23:52  volta_lemmon  阅读(4090)  评论(0)    收藏  举报