npm / npm/cli

[BUG] NPM clashes node file with PATH node on Windows

Open
#5,454 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Needs Triage Release 8.x
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

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

After a lot of back & forth, I've come to nail down a rare issue. When there's an npm script that calls node /some/file.js and there's a node.js file on the root where NPM is called, the script is invoked which results in an error.

Expected Behavior

Should not error.

Steps To Reproduce
  1. On windows
  2. Open PowerShell
  3. Run
mkdir test
cd test
npm init -y
  1. Create two files: index.js and node.js

Context of index.js:

console.log('test');

Context of node.js

module.exports = {};
  1. Update package.json to be like:
{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "test.js",
  "scripts": {
-    "test": "echo \"Error: no test specified\" && exit 1" 
+    "test": "node test.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}
  1. Run
npm t
  1. See error...

Screenshot 2022-09-01 at 16 24 38


If the file isn't present, it runs OK and outputs test on stdout as expected.

Environment
  • npm: 8.19.0
  • Node.js: 16.17.0
  • OS Name: Windows 11
  • System Model Name: Macbook Pro (VirtualBox machine)
  • npm config:
; node bin location = C:\Program Files\nodejs\node.exe
; node version = v16.17.0
; npm local prefix = C:\Users\User\Desktop\10up-toolkit
; npm version = 8.19.0
; cwd = C:\Users\User\Desktop\10up-toolkit\packages\eslint-config
; HOME = C:\Users\User
; Run `npm config ls -l` to show all defaults.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the Windows PowerShell case using package.json, index.js, and node.js, then run npm t with and without node.js present. Compare the command resolution and error behavior, and consider the issue done when the script runs successfully and prints the expected output in the reported setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.