已复制
全屏展示
复制代码

Ghost无法上传图片解决报500错误

· 1 min read

问题排查

在后台上传图片时接口直接报500错误,查看日志 content/logs/ 看到报错问题如下:

Error: Cannot find module 'sharp'
    at Object.resizeFromPath (/var/www/myblog/versions/5.70.1/node_modules/@tryghost/image-transform/lib/transform.js:127:31)
Require stack:
- /var/www/myblog/versions/5.70.1/node_modules/@tryghost/image-transform/lib/transform.js
- /var/www/myblog/versions/5.70.1/node_modules/@tryghost/image-transform/index.js
- /var/www/myblog/versions/5.70.1/core/frontend/helpers/img_url.js
- /var/www/myblog/versions/5.70.1/core/frontend/services/helpers/registry.js
- /var/www/myblog/versions/5.70.1/core/frontend/services/helpers/index.js
- /var/www/myblog/versions/5.70.1/core/frontend/services/apps/proxy.js
- /var/www/myblog/versions/5.70.1/core/frontend/services/apps/loader.js
- /var/www/myblog/versions/5.70.1/core/frontend/services/apps/index.js
- /var/www/myblog/versions/5.70.1/core/bridge.js
- /var/www/myblog/versions/5.70.1/core/server/services/route-settings/RouteSettings.js
- /var/www/myblog/versions/5.70.1/core/server/services/route-settings/index.js
- /var/www/myblog/versions/5.70.1/core/boot.js
- /var/www/myblog/versions/5.70.1/ghost.js
- /var/www/myblog/versions/5.70.1/index.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
    at Module._load (node:internal/modules/cjs/loader:922:27)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:119:18)
    at Object.resizeFromPath (/var/www/myblog/versions/5.70.1/node_modules/@tryghost/image-transform/lib/transform.js:125:9)
    at Object.query (/var/www/myblog/versions/5.70.1/core/server/api/endpoints/images.js:36:38)
    at Object.query (/var/www/myblog/versions/5.70.1/node_modules/@tryghost/api-framework/lib/pipeline.js:159:24)
    at /var/www/myblog/versions/5.70.1/node_modules/@tryghost/api-framework/lib/pipeline.js:259:35
    at async Http (/var/www/myblog/versions/5.70.1/node_modules/@tryghost/api-framework/lib/http.js:64:28)

这个问题在很早的版本就出现过,不知道为啥有出现了。

解决方法

修改配置 config.production.json,添加如下配置然后重启ghost即可

 "imageOptimization": {
    "resize": false
  }
🔗

文章推荐