pnpm: Not all required scripts installed after `pnpm i`. Error: Cannot find module '../build/Release/canvas.node'

Verify latest release

  • I verified that the issue exists in the latest pnpm release

pnpm version

8.12.1

Which area(s) of pnpm are affected? (leave empty if unsure)

Operating System (Windows, MacOS, Linux)

Link to the code that reproduces this issue or a replay of the bug

https://github.com/vtereshyn/pnpm-jest-jsdom-canvas

Reproduction steps

Having pdfjs-dist or canvas packages installed in your project run Jest tests in jsdom testing environment

Repository with reproduction attached:

pnpm install
pnpm test

Describe the Bug

Not all required scripts run on Apple M2 Processor, which causes an error:

Cannot find module '../build/Release/canvas.node'
    Require stack:
    - /Users/..../pnpm-jest-jsdom-canvas/node_modules/.pnpm/canvas@2.11.2/node_modules/canvas/lib/bindings.js

Please note that when using npm, everything works as expected. Also, on Intel processor everything works as expected either. Using npm, everything works as expected.

Issue happens only if you have canvas in your node_modules and in jsdom Jest environment. Removing pdfjs-dist and it’s peer dependency will resolve an issue, but that is not a solution

Expected Behavior

All required scripts run when running pnpm install

Which Node.js version are you using?

20.10.0

Which operating systems have you used?

  • macOS
  • Windows
  • Linux

If your OS is a Linux based, which one it is? (Include the version if relevant)

Using M2 processor

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 8
  • Comments: 37 (6 by maintainers)

Most upvoted comments

Still happening on an M1 Mac with pnpm 9.6 and node 22.4.1. Manually resolving with node-gyp didn’t work for me.

Since there are multiple comments saying it’s still happening, can this issue be reopened?

The issue is that the install script for the canvas package seems to be omitted when running pnpm install. To verify this, you can check the canvas folder within the node_modules directory. If you do not find a built folder, it means that the install script has been skipped.

This problem tends to occur during non-first-time installations. The root cause appears to me that it is a cache issue where pnpm mistakenly assumes that the package only needs to run the install script once during the first time installation and that any generated artifacts will be stored in the pnpm store. So, during subsequent installations, pnpm attempts to save time by merely cloning the stored artifacts, skipping the install script. However, in reality, the artifacts generated by the install script are left in the target folder, not in the store. Therefore, cloning misses these essential artifacts.

If I’ve misunderstood how pnpm works, please feel free to correct me, @zkochan.

@dlarr As my current workaround, I either run pnpm rebuild or pnpm store prune before pnpm install

Was still reproducible on M3.

Manually resolving dependencies for Canvas fixed the issue.

// ensure node-gyp is installed else 
npm install -g node-gyp

// find canvas dir
find . -type d | grep canvas

// navigate to canvas dir
cd ./.pnpm/canvas@2.11.2/node_modules/canvas

// manually resolve binaries
node-gyp rebuild 

My issue was I had to run pnpm approve-builds to give permission for the canvas install script to run. There was a warning about it somewhere but I didn’t see it among all the other output.

However, in reality, the artifacts generated by the install script are left in the target folder, not in the store. Therefore, cloning misses these essential artifacts.

I can confirm, the same is for zeromq@5.3.1 package. The first installation is ok. After removing node_modules and pnpm-lock.yaml, the second installation required setting side-effects-cache=false or running manually pnpm rebuild. Without it, an error is thrown:

Error: No native build was found for platform=darwin arch=arm64 runtime=node abi=108 uv=1 armv=8 libc=glibc node=18.18.2

@vtereshyn Try:

  1. brew install pkg-config cairo pango libpng jpeg giflib librsvg
  2. remove node_modules
  3. pnpm install
  4. pnpm rebuild

It resolves my issue CC: @zkochan

I see this error in the node-pre-gyp output:

ERR! install response status 404 Not Found on https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canvas-v2.11.2-node-v108-darwin-unknown-arm64.tar.gz

The “unknown” part in the URL bothers me. Maybe pnpm doesn’t pass some env variable to the executed script?

Node-canvas maintainer here. The “unknown” is fine (that’s your libc). The 404 is because you’re on an ARM CPU, and node-canvas prebuilds aren’t available for ARM. This is unrelated to the OP’s issue.

I have also experienced it, I tried installing the dependencies in the canvas library and that solved it for a short time however this issue has now reoccured after a mac update to Sonoma 14.7

Now I have tried all the steps here and it is not resolving the issue. This is a blocker for running a testing library as canvas is a dep for jest dom.

@vtereshyn I wish it’s the case too. But with shared-workspace-lockfile=false it’s not the case. It’s still broken.

@zkochan I’ve prepared a MRE to demonstrate the issue https://github.com/alvis/mre_pnpm_monorepo_package_dependency_build_skipped

When you install it you should see an error due to the missing build folder. If you comment shared-workspace-lockfile=false in .npmrc the build script of canvas will be run and hence the issue will be gone.

@javidmammad I wonder if this is the solution because this error also appears on a CI. Of course, I can do that for Linux using some pretest script, but I don’t have 100% confidence that this is correct way to solve that

But thank you for your suggestion!