首页 > 其他分享 >解决sharp太慢、失败Could not load js config file/strapi-server.js, pmSomething went wrong installing the &q

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

时间:2023-02-25 19:44:52浏览次数:52  
标签:load 13 Feb 22 Wed 55 js 2023 sharp

问题描述

项目在本地跑的好好地,使用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 [email protected]` to update!
Wed, Feb 22 2023 5:55:13 pmnpm notice

刚开始以为是自己的dockerfile写得有问题,我的dockerfile如下所示

FROM node:16-alpine as build
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/
COPY ./package.json ./yarn.lock ./
ENV PATH /opt/node_modules/.bin:$PATH
RUN yarn config set network-timeout 600000 -g && yarn install
WORKDIR /opt/app
COPY ./ .
RUN yarn build

FROM node:16-alpine
RUN apk add vips-dev
RUN rm -rf /var/cache/apk/*
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/app
COPY --from=build /opt/node_modules ./node_modules
ENV PATH /opt/node_modules/.bin:$PATH
COPY --from=build /opt/app ./
EXPOSE 8081

CMD ["yarn", "start"]

为了证明自己的dockerfile没有问题,我在本地安装了一个docker环境,运行以下命令执行代码,测试是否有异常

docker build -t web-test:v4 .| tee my-image.build.log
docker images
docker run -d -p 1337:1337 web-test:v4
docker logs --tail=1000 72fc083f1e8f14bd184f6539a64e897c6afd79ce466f76ca725761f5f6927574

如下图所示,项目在本地进行docker build ,run 一切正常,证明我的dockerfile没有问题

分析

原因一:先查看部署服务器的的项目依赖,是否是正确的node版本和npm版本,如果当前项目依赖的版本和实际环境有很大差异,会导致以上报错,对于我的项目来说,这个肯定是没问题

举个栗子:

原因二:网络不给力,导致没有下载成功包

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

问题解决

方案一:在项目目录下配置.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的镜像地址

如果你是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

方案三:把你的服务器网络搞一下~

今天就写到这里啦~

  • 小伙伴们,( ̄ω ̄( ̄ω ̄〃 ( ̄ω ̄〃)ゝ我们明天再见啦~~
  • 大家要天天开心哦

欢迎大家指出文章需要改正之处~
学无止境,合作共赢

在这里插入图片描述

欢迎路过的小哥哥小姐姐们提出更好的意见哇~~

标签:load,13,Feb,22,Wed,55,js,2023,sharp
From: https://www.cnblogs.com/sugartang/p/17155187.html

相关文章

  • JS之export
    export在创建JavaScript模块时,export语句用于从模块中导出实时绑定的函数、对象或原始值,以便其他程序可以通过import语句使用它们。被导出的绑定值依然可以在本地进......
  • ValueError: Object arrays cannot be loaded when allow_pickle=False
    问题展示:因为numpy在升级后将np.load()参数allow_pickle默认改为False。有两种解决方案:方法1:降低版本,降到1.16.3以下:先卸载当前的numpy,再下载指定版本的numpypipuninstall......
  • k8s workloads 练习
    练习主题练习deployment创建扩容所容练习pods自动扩所容和metric安装配置练习升级和回滚练习configmap创建和使用一命令创建创建depolymentnginx,副本为2kubectl......
  • OpenCvSharp 学习笔记1 -- 基本对象和常见操作
    一:Mat对象的创建OpenCvSharp版本:v4.0.30319mat对象继承了IDisposable接口,可以直接用using语句。mat对象的构造函数有十几个之多,我这里之列举常用的几个。Mat在C......
  • 【转载】js中var、let、const的区别
    var、let、constvar1.var声明作用域functiontest(){varmessage="hi";//局部变量}test();console.log(message);//报错!message未定义 这里,message变量是函数内......
  • for in (var key in Obj)遍历JS对象/数组
    这个方法还可以遍历数组,就放在一起写了。letresult=function(obj){for(letkeyinobj){returnfalse;//若不为空,可遍历,返回false}returntrue;}conso......
  • JS 删除对象中的某个属性
    方法1删除是删除对象的属性没有任何剩菜剩下的唯一真正的方法但它的工作比其“替代”设置慢100倍object[key]=undefinedvarmyObject={"ircEvent":"PRIVMSG",......
  • js获取时区偏移量
    需求时间要求显示如下,需要带上时区偏移量2023/02/2120:40:47+08:00js如何计算这个偏移量执行getTimezoneOffset()方法会返回UTC相对于当前时区的相差分钟数。我们只需......
  • js实战-删除指定行、控制键盘的输入
    资料来源于:B站尚硅谷JavaWeb教程(全新技术栈,全程实战),本人才疏学浅,记录笔记以供日后回顾删除指定行、控制键盘的输入的视频链接个人总结知识点1.本节主要目的:(1)当......
  • 日期对象js
    实例化1.得到当前时间consttime=newDate()console.log(time)//SatFeb25202310:59:18GMT+0800(中国标准时间)!!!在node端得到的时间是2023-02-25T02:58:46.3......