Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Starting with v10.4.0, --include=optional not working (for transitive dependency (sharp)) #7406

Closed
2 tasks done
bhallstein opened this issue Apr 23, 2024 · 4 comments
Closed
2 tasks done
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 10.x

Comments

@bhallstein
Copy link

bhallstein commented Apr 23, 2024

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

We are deploying an app that uses the sharp image manipulation library. A deployment bundle is built on macs, with npm i --cpu=x64 --os=linux --include=optional [email protected] called afterwards to install cross-platform deps that can't be bundled, following which a tarball is created and used for deployments.

On [email protected] and below, after running the above npm i command node_modules contains dirs for sharp and also the platform-specific transitive dependencies, @img/sharp-linux-x64, @img/sharp-libvips-linux-x64, etc.

Starting with [email protected], sharp is installed but @img/... is not, breaking our deployments.

Expected Behavior

I believe the [email protected] behaviour is correct, the platform-specific transitive deps should be installed.

Steps To Reproduce

  1. Latest node, [email protected] or 10.5.0

  2. With this config: none needed

  3. Run:

mkdir temp; cd temp
npm i --cpu=x64 --os=linux --include=optional [email protected]
  1. Note that node_modules/@img is an empty directory.

Environment

  • npm: 10.4.0, 10.5.0, 10.5.2
  • Node.js: 21.7.2
  • OS Name: macOS Sonoma 14.4.1
  • System Model Name: Mac Mini M1
  • npm config:
; "builtin" config from /opt/homebrew/lib/node_modules/npm/npmrc

prefix = "/opt/homebrew" 

; "user" config from /Users/xyz/.npmrc

//registry.npmjs.org/:_authToken = (protected) 

; node bin location = /opt/homebrew/Cellar/node/21.7.3/bin/node
; node version = v21.7.3
; npm version = 10.3.0
; HOME = /Users/xyz
; Run `npm config ls -l` to show all defaults.
@bhallstein
Copy link
Author

Further, tested on ubuntu as well, where cross-compilation continues to work on 10.5.0:

Mac:

Desktop:$ mkdir temp; cd temp
temp:$ node -p "[process.arch,process.platform]"
[ 'arm64', 'darwin' ]
temp:$ npm -v
10.5.0
temp:$ npm i --cpu=x64 --os=linux --include=optional [email protected]
added 11 packages in 1s
temp:$ ls -l node_modules/\@img/
total 0

Ubuntu:

muffins@localhost:~$ mkdir temp; cd temp
muffins@localhost:~/temp$ npm -v
10.5.0
muffins@localhost:~/temp$ npm i --cpu=arm64 --os=darwin --include=optional [email protected]
added 13 packages in 9s
muffins@localhost:~/temp$ ls -l node_modules/@img/
total 8
drwxrwxr-x 3 muffins muffins 4096 Apr 23 17:31 sharp-darwin-arm64
drwxrwxr-x 3 muffins muffins 4096 Apr 23 17:31 sharp-libvips-darwin-arm64

@bhallstein
Copy link
Author

bhallstein commented Apr 24, 2024

After some more digging over on lovell/sharp#4080 we found that on 10.4.0+ --libc=glibc is needed for the platform-specific deps to be installed when cross-compiling sharp from mac to linux. 10.3.0 and older it works without this.

At this point I'm uncertain if this is a regression in npm, or intended behaviour. I looked at the release notes but couldn't immediately see a justification for the change. The behaviour may reside in https://github.com/npm/npm-install-checks

@wraithgar
Copy link
Member

This is one of those tricky situations where a bug was fixed and some folks may have been relying on the broken behavior. The fix was in arborist. The minified packument didn't include the libc field from the manifest so npm didn't know not to install it.

npm is now currently behaving as intended.

@bhallstein
Copy link
Author

Thanks for clarifying @wraithgar 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 10.x
Projects
None yet
Development

No branches or pull requests

2 participants