Skip to content

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

@t1m0thyj

Description

@t1m0thyj

Current Behavior:

In a workspace, npm install fails for a package with a "bin" script defined in package.json that doesn't exist. NPM tries to chmod the non-existent "bin" script, resulting in ENOENT error.

npm ERR! code ENOENT
npm ERR! syscall chmod
npm ERR! path /home/timothy/dev/npm7-bin-link-issue/node_modules/cli/lib/index.js
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, chmod '/home/timothy/dev/npm7-bin-link-issue/node_modules/cli/lib/index.js'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

Expected Behavior:

npm install should succeed and NPM should not attempt to chmod "bin" scripts if they don't exist.

Steps To Reproduce:

The scenario of a non-existent "bin" script is easy to encounter in a TypeScript monorepo using NPM workspaces, where a "bin" script may point to a .js file that doesn't exist until the TS is transpiled to JS.

To reproduce the error, clone this minimal sample repo and run npm install. Or follow the steps below:

  1. Create an NPM project: npm init -y
  2. Define the workspaces property in top-level package.json:
    "workspaces": [ "./packages/*" ]
  3. Create the directory structure "packages/cli" and generate a package.json there: cd packages/cli && npm init -y
  4. Define bin property in "packages/cli/package.json" and point to a non-existent script:
    "bin": { "test-cli": "./nonexistent.js" }
  5. Run npm install at top level of project and see ENOENT

Environment:

  • OS: Ubuntu 18.04
  • Node: 15.8.0
  • npm: 7.5.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingPriority 2secondary priority issueRelease 7.xwork is associated with a specific npm 7 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions