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] Install fails if "bin" script doesn't exist #4597

Closed
2 tasks done
remcohaszing opened this issue Mar 22, 2022 · 3 comments · Fixed by npm/bin-links#80
Closed
2 tasks done

[BUG] Install fails if "bin" script doesn't exist #4597

remcohaszing opened this issue Mar 22, 2022 · 3 comments · Fixed by npm/bin-links#80
Labels
Bug thing that needs fixing Priority 2 secondary priority issue Release 8.x work is associated with a specific npm 8 release

Comments

@remcohaszing
Copy link

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

This is a duplicate of #2632. This has been closed, but I still encounter it using the latest version of npm.

When running npm install in a project that references a bin script that doesn’t exist, the command fails with the error:

npm ERR! code ENOENT
npm ERR! syscall chmod
npm ERR! path /home/remco/Projects/appsemble/node_modules/@appsemble/server/dist/index.js
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, chmod '/home/remco/Projects/appsemble/node_modules/@appsemble/server/dist/index.js'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

Expected Behavior

npm install is succesful

Steps To Reproduce

git clone git@gitlab.com:appsemble/appsemble.git
cd appsemble
rm yarn.lock
npm install

Environment

  • npm: 8.5.5
  • Node.js: 16.14.2
  • OS Name: Pop!_OS
  • System Model Name:
  • npm config:
; "global" config from /home/remco/.local/etc/npmrc

fund = false 

; node bin location = /usr/bin/node
; cwd = /home/remco/Projects/appsemble
; HOME = /home/remco
; Run `npm config ls -l` to show all defaults
@remcohaszing remcohaszing added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels Mar 22, 2022
@fritzy
Copy link
Contributor

fritzy commented Mar 30, 2022

#2632 possible regression

@fritzy fritzy added Priority 2 secondary priority issue and removed Needs Triage needs review for next steps labels Mar 30, 2022
@remcohaszing
Copy link
Author

The issue still exists today in npm 9.

The issue occurs when two packages install the same executable name, but it doesn’t exist in the second package that is supposed to install that executable.

It’s simplest to reproduce with npm workspaces, but it applies to other dependencies as well.

Let’s say we have the following files:

package.json

{
  "workspaces": [
    "workspaces/*"
  ]
}

workspaces/a/package.json

{ 
  "name": "a",
  "bin": {
    "cli": "./cli.js"
  }
}

workspaces/b/package.json

{ 
  "name": "b",
  "bin": {
    "cli": "./cli.js"
  }
}

Running npm install from this project will reproduce the issue.

If we create an empty file workspaces/a/cli.js, the issue still exists. However, if we create an empty file workspaces/b/cli.js instead, the issue goes away.

@remcohaszing
Copy link
Author

The problem is in https://github.com/npm/bin-links/blob/v4.0.1/lib/link-gently.js#L30-L33. This naively returns true if a link target was seen before. This indicates the file was linked succesfully. Then https://github.com/npm/bin-links/blob/main/lib/link-bin.js#L7 will try to make the non-existent file executable, which makes npm fail.

wraithgar pushed a commit to npm/bin-links that referenced this issue Jul 11, 2023
`linkGently` would return true if a link target had been visited before.
`linkBin` would then chmod the link `to`, regardless of whether this
file exists. This causes `npm install` to fail if multiple packages link
to a non-existent bin with the same name.

By returning false in `linkGently`, `linkBin` no skips the chmod on the
non-existent file.


## References

Fixes npm/cli#4597
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Priority 2 secondary priority issue Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants