Cannot find module 'canvas' - cloud build only

Local builds and runs but fails in cloud with same NODE_VERSION.
NODE_VERSION=16.17.0 is used on local and in Netlify deploy environment variables

The failed dependency (canvas) is pulled in from svelte-pdf-simple, so we know the source of the problem, but where should we look for an indication about what is different in our local that causes it to build, from the Netlify build, where the dependency is not found?


  "type": "module",
  "dependencies": {
    "@fortawesome/free-regular-svg-icons": "^6.0.0",
    "cookie": "^0.4.1",
    "encoding": "^0.1.13",
    "fathom-client": "^3.1.0",
    "faunadb": "^4.7.0",
    "graphql": "^15.7.2",
    "graphql-combine-query": "^1.2.3",
    "mini-signals": "^1.2.0",
    "node-fetch": "^3.1.0",
    "sib-api-v3-sdk": "^8.3.0",
    "svelte-fa": "^2.4.0",
    "svelte-pdf-simple": "^2.0.0",
    "uuid": "^8.3.2"

After npm -install, package-lock.json is checked in

Builds run locally complete and run without error
npm run build
npm run dev
all good on local but fails in the Netlify build:

build log

8:50:36 PM:   A Netlify Function failed to require one of its dependencies.
8:50:36 PM:   Please make sure it is present in the site's top-level "package.json".
8:50:36 PM:   In file "/opt/build/repo/.netlify/functions-internal/render.js"
8:50:36 PM:   Cannot find module 'canvas'
8:50:36 PM:   Require stack:

Netlify deploy Environment variable NODE_VERSION=16.17.0, same as local.

Obviously the problem is a missing dependency (canvas) introduced by svelte-pdf-simple, but there shouldn’t there be some evidence of the discrepancy between the successful local build and failed Netlify build?

netlify.toml is

command = “npm run build”
publish = “build”
functions = “functions”


Hi @mgodeck, there is a post here on the forums that experienced the same error you are experiencing.

Kindly try the suggestions in the post below and let me know the outcome.


Thank @clarnx but pinning to @sveltejs/adapter-netlify": "^1.0.0-next.65 did not change outcomes for us: local build is successful, Netlify build still fails.

Any additional clues appreciated for where to look for discrepancies between local and cloud build! Thanks

Hi @mgodeck, remove the lockfile (package-lock.json) in your project. After run

npm i @netlify/plugin-nextjs --save-dev 

Let me know the outcome.

This issue is resolved by removing our use of svelte-pdf-simple, although of course we’d already tried that before opening this ticket. It was a bit of a rabbit hole of node version bingo and all it can say is we’re back up.

Still, any guidance will be appreciated on how to approach the problem node dependency breaks the Netlify build breaks that are not evidenced in the local build. Some things that come to mind:

  • check the version of the npm executable,
  • check that the node version is the same,
  • that package-lock.json is checked in,
  • that you’ve tried deleting and regenerating package-lock.json

what else?

Hi @mgodeck, thanks for the feedback.
At this point if svelte-pdf-simple is still giving you problems you can try out an an alternative package called svelte-pdf
to see if it helps. svelte-pdf has most of the features of svelte-pdf-simple.

Another option is to create a minimal production site with only svelte-pdf-simple installed as a package to see if it will work.
Sometimes creating a minimal reproduction site can help rule out possible causes.