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)
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: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.