[BUG] Newlines are handled differently between node and `npm exec` on powershell
Nobody has claimed this yet.
- 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
Using the following script:
#!/usr/bin/env node
console.log(process.argv[process.argv.length - 1]);
and package.json with "bin": "./index.js",.
When I run the script with multiline arguments in node and npx, I get the different results on Powershell:
PowerShell 7.4.5/Windows 11
Note there is a missing second line on the npx output
PS > node .\index.js "a`nb"
a
b
PS > npx . "a`nb"
a
bash/linux
root@host:/app# node index.js $'a\nb'
a
b
root@host:/app# npx . $'a\nb'
a
b
Expected Behavior
Since I'm writing a CLI tool that relies heavily on multiline arguments, I expected the same behaviour between shells:
PowerShell 7.4.5/Windows 11
PS > node .\index.js "a`nb"
a
b
PS > npx . "a`nb"
a
b
bash
root@host:/app# node index.js $'a\nb'
a
b
root@host:/app# npx . $'a\nb'
a
b
A similar bug was fixed under bash at some time, however, it persists in windows environments.
Steps To Reproduce
- Use the script provided above
- Run sample commands
Environment
- npm: 10.8.2
- Node.js: v20.18.0 and v22.8.0 (managed with nvm-windows)
- OS Name: Windows 11
- System Model Name: Custom Desktop PC
- Terminal: Windows Terminal
- Shell: PowerShell 7.4.5
- npm config:
//registry.npmjs.org/:_authToken = (protected)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided index.js and package.json, then reproduce the commands in PowerShell and bash to compare node with npx. Trace npm exec's Windows argument-forwarding path and verify that a multiline argument retains both lines, matching direct node execution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs, powershell
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100