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 7 months ago
  • Reactions: 2
  • Comments: 26 (6 by maintainers)

Most upvoted comments

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

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