Sharp package Heroku deployment issue
Asked Answered
A

3

7

I'm deploying my NodeJs app to Heroku. No issues running the app with nodemon locally.

However when I'm trying to push to Heroku Master, seems like "sharp" package is causing an issue:

remote: -----> Installing dependencies

remote: Installing node modules (package.json + package-lock)

remote:

remote: > [email protected] install /tmp/build_4cfeda2379ea362c72ac083b57638cce/node_modules/sharp

remote: > (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)

remote:

remote: info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.7.4/libvips-8.7.4-linux-x64.tar.gz

remote:
/tmp/build_4cfeda2379ea362c72ac083b57638cce/node_modules/sharp/install/libvips.js:86

remote: throw new Error(Status ${response.statusCode});

remote: ^

remote:

remote: Error: Status 403

remote: at /tmp/build_4cfeda2379ea362c72ac083b57638cce/node_modules/sharp/install/libvips.js:86:17

remote: at f (/tmp/build_4cfeda2379ea362c72ac083b57638cce/node_modules/once/once.js:25:25)

remote: at ClientRequest.protocol.request.res (/tmp/build_4cfeda2379ea362c72ac083b57638cce/node_modules/simple-get/index.js:63:5)

remote: at Object.onceWrapper (events.js:277:13)

remote: at ClientRequest.emit (events.js:189:13)

remote: at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:556:21)

remote: at HTTPParser.parserOnHeadersComplete (_http_common.js:109:17)

remote: at TLSSocket.socketOnData (_http_client.js:442:20)

remote: at TLSSocket.emit (events.js:189:13)

remote: at addChunk (_stream_readable.js:284:12)

remote: make: Entering directory '/tmp/build_4cfeda2379ea362c72ac083b57638cce/node_modules/sharp/build'

remote: TOUCH Release/obj.target/libvips-cpp.stamp

remote: CXX(target) Release/obj.target/sharp/src/common.o

remote: ../src/common.cc:25:10: fatal error: vips/vips8: No such file or directory

remote: #include

remote: ^~~~~~~~~~~~

remote: compilation terminated.

remote: sharp.target.mk:128: recipe for target 'Release/obj.target/sharp/src/common.o' failed

remote: make: *** [Release/obj.target/sharp/src/common.o] Error 1

remote: make: Leaving directory '/tmp/build_4cfeda2379ea362c72ac083b57638cce/node_modules/sharp/build'

Update:

Try removing sharp from package.json and add it back again using npm install sharp works this time... I still don't know why.

remote: -----> Installing dependencies

remote: Installing node modules (package.json + package-lock)

remote:

remote: > [email protected] install /tmp/build_5c8d3b01594e0b86f9d3e0d372534414/node_modules/sharp

remote: > (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)

remote:

remote: info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.7.4/libvips-8.7.4-linux-x64.tar.gz

remote: added 57 packages from 92 contributors and audited 20393 packages in 10.683s

remote: found 62 low severity vulnerabilities

remote: run npm audit fix to fix them, or npm audit for details

remote:

remote: -----> Build

remote:

remote: -----> Caching build

remote: - node_modules

remote:

remote: -----> Pruning devDependencies

remote: removed 606 packages and audited 497 packages in 8.181s

remote: found 0 vulnerabilities

remote:

remote:

remote: -----> Build succeeded!

Armillda answered 29/3, 2019 at 9:29 Comment(7)
Anyone having the same issue? Or are there any alternative for sharp package for image compression?Armillda
I was able to use sharp in Heroku using official document only, you can use gm(npmjs.com/package/gm) module as an alternativePrentice
I hope you are not pushing node_modules folder as well?Pesthouse
Thanks @Gomzy for your recommendation, I was able to deploy it on Heroku now using sharpArmillda
@AsgharMusani, thx. I've already added it to .gitignore before pushing it, don't think it's caused by that. Perhaps I'll migrate to AWS to prevent this sort of issue from happening again.Armillda
@Armillda can you please post a solution, if possible? So that other devs can solve it easily if there are running into the same issue.Prentice
@Gomzy I would like to post a solution, however, I don't have a concrete solution for now.Armillda
T
8

There are many people with that problem, it's related to libvips as dependency not sharp by itself.

On github in this issue-comment the problem is explained:

The pre-built binaries of sharp are only guaranteed to work with the pre-built binaries of libvips.

If the download of a pre-built binary of libvips fails then sharp has to fall back to attempting to build itself from source.

http://sharp.pixelplumbing.com/en/stable/install/#pre-compiled-libvips-binaries provides information about serving the libvips binaries from a local URL.

The reason why the download is failing might be the cache, or a corrupted download like reported in the above linked issue on github:

I had to manually remove the ~/.npm/_libvips/libvips-8.7.0-linux-x64.tar.gz and try again. Seems to be downloaded a corrupted file.

Here is an interesting discussion concerning the same problem related to gatsby, a solution seems not yet existing even the issue was closed (before any comment was made): https://github.com/gatsbyjs/gatsby/issues/1754

However if the problem is only related to the download for some reason it's possible to deploy libvips locally like explained in the manual:

Pre-compiled libvips binaries
This module will attempt to download a pre-compiled bundle of libvips and its dependencies on Linux and Windows machines under either of these conditions:

  • If a global installation of libvips that meets the minimum version
    requirement cannot be found;
  • If SHARP_IGNORE_GLOBAL_LIBVIPS environment variable is set.
SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm install sharp  

Should you need to manually download and inspect these files,
you can do so via https://github.com/lovell/sharp-libvips/releases

Should you wish to install these from your own location, set the
sharp_dist_base_url npm config option, e.g.

npm config set sharp_dist_base_url "https://hostname/path/" 
npm install sharp 

or set the SHARP_DIST_BASE_URL environment variable, e.g.

SHARP_DIST_BASE_URL="https://hostname/path/" npm install sharp

to use https://hostname/path/libvips-x.y.z-platform.tar.gz.

So this is a bit background, I'm aware that this can not really be seen as an answer with solution :/

Toul answered 8/4, 2019 at 1:36 Comment(0)
G
2

If someone reaches here and didn't found an answer - my issue was that my project was using an old node version (8.x)

The solution was to install an older version of sharp - The latest one that support 8.x - "sharp": "0.23.4"

Goliath answered 26/11, 2020 at 20:54 Comment(0)
J
0

As David mentioned, this seemed to be related to the wrong pre-built binaries being pulled in. In my case, my package-lock referenced windows/macos binaries, but left out the linux binaries. The solution is to directly tell npm (or any other package manager) to pull in the linux binaries that Heroku uses:

npm install --os=linux --cpu=x64 sharp

More information can be found here

https://sharp.pixelplumbing.com/install#cross-platform

Jeanicejeanie answered 12/4 at 18:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.