zip-it-and-ship-it: Problem with running Netlify function: Cannot find module '../build/Release/sharp.node'

- Do you want to request a feature or report a bug? bug

- What is the current behavior? I’m including the sharp module in my deploy-building.js Netlify function. I’m resizing some images and uploading them to an S3 bucket.

When invoking the function in the Netlify dev environment, it works. However, when I deploy my feature branch in a deploy preview, it does not work. These are the logs from building the site (that are relevant to sharp):

3:15:43 PM: Different functions path detected, going to use the one specified in the Netlify configuration file: 'functions/' versus '' in the Netlify UI
3:15:43 PM: Creating functions prep folder
3:15:43 PM: Starting build script
3:15:43 PM: Installing dependencies
3:15:45 PM: Started restoring cached node version
3:15:52 PM: Finished restoring cached node version
3:15:53 PM: v10.18.1 is already installed.
3:15:55 PM: Now using node v10.18.1 (npm v6.13.4)
3:15:55 PM: Attempting ruby version 2.6.2, read from environment
3:15:57 PM: Using ruby version 2.6.2
3:15:57 PM: Using PHP version 5.6
3:15:57 PM: Started restoring cached node modules
3:15:57 PM: Finished restoring cached node modules
3:15:58 PM: Installing NPM modules using NPM version 6.13.4
3:16:12 PM: > sharp@0.23.4 install /opt/build/repo/node_modules/sharp
3:16:12 PM: > (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
3:16:12 PM: info
3:16:12 PM: sharp
3:16:12 PM:  Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.8.1/libvips-8.8.1-linux-x64.tar.gz
3:16:17 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.0 (node_modules/chokidar/node_modules/fsevents):
3:16:17 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.0: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
3:16:17 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
3:16:17 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
3:16:17 PM: added 41 packages from 148 contributors and audited 20682 packages in 17.73s
.
.
.
3:16:49 PM: Function Dir: /opt/build/repo/functions
3:16:49 PM: TempDir: /tmp/zisi-5e1f80e7ef244ae910e5a4cc
3:16:49 PM: Prepping functions with zip-it-and-ship-it 0.3.1
3:16:51 PM: [ { path: '/tmp/zisi-5e1f80e7ef244ae910e5a4cc/deploy-building.zip',
3:16:51 PM:     runtime: 'js' },
3:16:51 PM:   { path: '/tmp/zisi-5e1f80e7ef244ae910e5a4cc/submission-created.zip',
3:16:51 PM:     runtime: 'js' } ]
3:16:51 PM: Prepping functions complete
3:16:51 PM: Caching artifacts
3:16:51 PM: Started saving node modules
3:16:51 PM: Finished saving node modules
3:16:51 PM: Started saving pip cache
3:16:51 PM: Finished saving pip cache
3:16:51 PM: Started saving emacs cask dependencies
3:16:51 PM: Finished saving emacs cask dependencies
3:16:51 PM: Started saving maven dependencies
3:16:51 PM: Finished saving maven dependencies
3:16:51 PM: Started saving boot dependencies
3:16:52 PM: Finished saving boot dependencies
3:16:52 PM: Started saving go dependencies
3:16:52 PM: Finished saving go dependencies
3:16:52 PM: Build script success

Here are the function’s logs when it tries to run:

3:15:26 PM: 2020-01-15T21:15:26.407Z	undefined	ERROR	
Something went wrong installing the "sharp" module

Cannot find module '../build/Release/sharp.node'

- Remove the "node_modules/sharp" directory, run "npm install" and look for errors
- Consult the installation documentation at https://sharp.pixelplumbing.com/en/stable/install/
- Search for this error at https://github.com/lovell/sharp/issues

- If the current behavior is a bug, please provide the steps to reproduce.

  1. Have a JS Netlify function deploy-building.js that requires sharp: const sharp = require('sharp');
  2. Push to Github PR, which notifies Netlify to publish a deploy preview. (We have Netlify configured to deploy PRs automatically.)
  3. Site builds, but because deploy-building.js did not exist yet, it will not have run during the very first build.
  4. Retry deploy in Netlify’s UI.
  5. deploy-building.js runs and logs that something went wrong with sharp.

- What is the expected behavior?

I expect my function to be able to find and use the sharp module.

- Please mention your node.js, and operating system version.

Locally, I’m using node v11.9.0. I’m on a MacBook Pro running macOS Mojave v10.14.5.

I understand that sharp is a native module, and that it installs a different version for me locally than it installs on Netlify, so I don’t think it’s a differing environments issue.

I also set the AWS_LAMBDA_JS_RUNTIME environment variable on Netlify to nodejs10.x, mostly because I was running out of ideas and I thought maybe it would help because of what I had been reading in sharp’s installation docs: https://sharp.pixelplumbing.com/en/stable/install/#aws-lambda

At any rate, it was giving me the same errors before I set that variable.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 18 (9 by maintainers)

Most upvoted comments

Can someone please post a repo that reproduces this issue? I was able to run sharp successfully inside a Netlify function with 2 different configurations:

  1. sharp installed as a dependency in the root package.json
  2. sharp installed using @netlify/plugin-functions-install-core from a package.json inside the functions directory

I created a brand new site, so my function node version is 12, which seems to be a requirement: https://sharp.pixelplumbing.com/install#aws-lambda

I’m using the default build image Ubuntu Xenial 16.04 (default), installing dependecies with yarn and set YARN_VERSION = "1.22.4" and NODE_VERSION = "12".

My function is a simple image resizer: https://github.com/erezrokah/netlify-build-reproductions/blob/zip-it-and-ship-it/issue_79/functions/sharp.js

I’ll try reproducing with npm, but recommend clearing build cache for debugging purposes and try adding the following to the build command:

rm -rf node_modules/sharp
npm install --arch=x64 --platform=linux sharp

As suggested https://sharp.pixelplumbing.com/install#aws-lambda

Update

works with npm too https://github.com/erezrokah/netlify-build-reproductions/tree/zip-it-and-ship-it/issue_79_npm

Closing this as stale, please comment if still relevant

@caramiki I am going to look into this.

Could you first please confirm you are using zip-it-and-ship-it@v0.4.0-8 and not zip-it-and-ship-it@v0.4.0-7?