Skip to content

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

Open
@rgembalik

Description

@rgembalik

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingPriority 2secondary priority issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions