npm / npm/cli

[BUG] Newlines are handled differently between node and `npm exec` on powershell

Open
#7,830 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Priority 2
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
  1. Use the script provided above
  2. 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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.