解决sharp太慢、失败Could not load js config file/strapi-server.js, pmSomething went wrong installing the “sharp” module 

2024-1-19 61 1/19

问题描述

项目在本地跑的好好地,使用Windows电脑和MAC电脑,重新下载依赖运行项目均无异常。

使用docker部署项目,遇到如下报错

[2023-02-22 09:55:13.784] debug: ⛔️ Server wasn't able to start properly.
Wed, Feb 22 2023 5:55:13 pm[2023-02-22 09:55:13.786] error: Could not load js config file /opt/app/node_modules/@strapi/plugin-upload/strapi-server.js:
Wed, Feb 22 2023 5:55:13 pmSomething went wrong installing the "sharp" module
Wed, Feb 22 2023 5:55:13 pm
Wed, Feb 22 2023 5:55:13 pmCannot find module '../build/Release/sharp-linuxmusl-x64.node'
Wed, Feb 22 2023 5:55:13 pmRequire stack:
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/plugin-upload/node_modules/sharp/lib/sharp.js
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/plugin-upload/node_modules/sharp/lib/constructor.js
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/plugin-upload/node_modules/sharp/lib/index.js
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/plugin-upload/server/services/image-manipulation.js
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/plugin-upload/server/services/index.js
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/plugin-upload/server/index.js
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/plugin-upload/strapi-server.js
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/utils/lib/import-default.js
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/utils/lib/index.js
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/strapi/lib/Strapi.js
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/strapi/lib/index.js
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/strapi/lib/commands/start.js
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/strapi/bin/strapi.js
Wed, Feb 22 2023 5:55:13 pm
Wed, Feb 22 2023 5:55:13 pmPossible solutions:
Wed, Feb 22 2023 5:55:13 pm- Install with verbose logging and look for errors: "npm install --ignore-scripts=false --foreground-scripts --verbose sharp"
Wed, Feb 22 2023 5:55:13 pm- Install for the current linuxmusl-x64 runtime: "npm install --platform=linuxmusl --arch=x64 sharp"
Wed, Feb 22 2023 5:55:13 pm- Consult the installation documentation: https://sharp.pixelplumbing.com/install
Wed, Feb 22 2023 5:55:13 pmError: Could not load js config file /opt/app/node_modules/@strapi/plugin-upload/strapi-server.js:
Wed, Feb 22 2023 5:55:13 pmSomething went wrong installing the "sharp" module
Wed, Feb 22 2023 5:55:13 pm
Wed, Feb 22 2023 5:55:13 pmCannot find module '../build/Release/sharp-linuxmusl-x64.node'
Wed, Feb 22 2023 5:55:13 pmRequire stack:
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/plugin-upload/node_modules/sharp/lib/sharp.js
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/plugin-upload/node_modules/sharp/lib/constructor.js
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/plugin-upload/node_modules/sharp/lib/index.js
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/plugin-upload/server/services/image-manipulation.js
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/plugin-upload/server/services/index.js
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/plugin-upload/server/index.js
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/plugin-upload/strapi-server.js
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/utils/lib/import-default.js
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/utils/lib/index.js
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/strapi/lib/Strapi.js
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/strapi/lib/index.js
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/strapi/lib/commands/start.js
Wed, Feb 22 2023 5:55:13 pm- /opt/app/node_modules/@strapi/strapi/bin/strapi.js
Wed, Feb 22 2023 5:55:13 pm
Wed, Feb 22 2023 5:55:13 pmPossible solutions:
Wed, Feb 22 2023 5:55:13 pm- Install with verbose logging and look for errors: "npm install --ignore-scripts=false --foreground-scripts --verbose sharp"
Wed, Feb 22 2023 5:55:13 pm- Install for the current linuxmusl-x64 runtime: "npm install --platform=linuxmusl --arch=x64 sharp"
Wed, Feb 22 2023 5:55:13 pm- Consult the installation documentation: https://sharp.pixelplumbing.com/install
Wed, Feb 22 2023 5:55:13 pmat loadJsFile (/opt/app/node_modules/@strapi/strapi/lib/core/app-configuration/load-config-file.js:18:11)
Wed, Feb 22 2023 5:55:13 pmat loadFile (/opt/app/node_modules/@strapi/strapi/lib/core/app-configuration/load-config-file.js:35:14)
Wed, Feb 22 2023 5:55:13 pmat Object.loadPlugins (/opt/app/node_modules/@strapi/strapi/lib/core/loaders/plugins/index.js:95:26)
Wed, Feb 22 2023 5:55:13 pmat async Strapi.loadPlugins (/opt/app/node_modules/@strapi/strapi/lib/Strapi.js:333:5)
Wed, Feb 22 2023 5:55:13 pmat async Promise.all (index 2)
Wed, Feb 22 2023 5:55:13 pmat async Strapi.register (/opt/app/node_modules/@strapi/strapi/lib/Strapi.js:369:5)
Wed, Feb 22 2023 5:55:13 pmat async Strapi.load (/opt/app/node_modules/@strapi/strapi/lib/Strapi.js:474:5)
Wed, Feb 22 2023 5:55:13 pmat async Strapi.start (/opt/app/node_modules/@strapi/strapi/lib/Strapi.js:212:9)
Wed, Feb 22 2023 5:55:13 pmnpm notice
Wed, Feb 22 2023 5:55:13 pmnpm notice New major version of npm available! 8.19.3 -> 9.5.0
Wed, Feb 22 2023 5:55:13 pmnpm notice Changelog: <https://github.com/npm/cli/releases/tag/v9.5.0>
Wed, Feb 22 2023 5:55:13 pmnpm notice Run `npm install -g npm@9.5.0` to update!
Wed, Feb 22 2023 5:55:13 pmnpm notice

网络不给力,导致没有下载成功包

这个就不赘述了,这个是我们最容易遇到的,也是我这次部署遇到的情况

 

如果你是npm 
npm config set sharp_binary_host "https://npm.taobao.org/mirrors/sharp"
npm config set sharp_libvips_binary_host "https://npm.taobao.org/mirrors/sharp-libvips"
npm install sharp
如果你是yarn 
设置 sharp_binary_host镜像地址
yarn config set sharp_binary_host "https://npm.taobao.org/mirrors/sharp"
设置 sharp_libvips_binary_host镜像地址
yarn config set sharp_libvips_binary_host "https://npm.taobao.org/mirrors/sharp-libvips"
yarn add sharp
- THE END -

非特殊说明,本博所有文章均为博主原创。

共有 0 条评论