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)
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
installscript for thecanvaspackage seems to be omitted when runningpnpm install. To verify this, you can check thecanvasfolder within thenode_modulesdirectory. If you do not find abuiltfolder, it means that theinstallscript 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
installscript 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 theinstallscript. However, in reality, the artifacts generated by theinstallscript 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 rebuildorpnpm store prunebeforepnpm installWas still reproducible on M3.
Manually resolving dependencies for Canvas fixed the issue.
My issue was I had to run
pnpm approve-buildsto 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.I can confirm, the same is for
zeromq@5.3.1package. The first installation is ok. After removingnode_modulesandpnpm-lock.yaml, the second installation required settingside-effects-cache=falseor running manuallypnpm rebuild. Without it, an error is thrown:@vtereshyn Try:
It resolves my issue CC: @zkochan
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=falseit’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
buildfolder. If you commentshared-workspace-lockfile=falsein.npmrcthe 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!