Problem with running Netlify function: Cannot find module '../build/Release/sharp.node'
See original GitHub issue- 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.
- Have a JS Netlify function
deploy-building.jsthat requires sharp:const sharp = require('sharp'); - Push to Github PR, which notifies Netlify to publish a deploy preview. (We have Netlify configured to deploy PRs automatically.)
- Site builds, but because
deploy-building.jsdid not exist yet, it will not have run during the very first build. - Retry deploy in Netlify’s UI.
deploy-building.jsruns 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.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:18 (9 by maintainers)

Top Related StackOverflow Question
Can someone please post a repo that reproduces this issue? I was able to run
sharpsuccessfully inside a Netlify function with 2 different configurations:sharpinstalled as a dependency in the rootpackage.jsonsharpinstalled using@netlify/plugin-functions-install-corefrom apackage.jsoninside the functions directoryI 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 withyarnand setYARN_VERSION = "1.22.4"andNODE_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: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