npm / npm/cli

[BUG] `npm run` erases script output after the final newline

Open
#8,583 8 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

Any script which writes to standard output but does not emit a \n as its final character will have output erased when npm run exits.

Expected Behavior

npm run should never interfere with the output of scripts.

Steps To Reproduce
  1. Create a package.json file like this:
    {
      "name": "",
      "version": "0.0.0",
      "scripts": {
        "start": "printf 'this output will vanish'; sleep 3"
      }
    }
    
  2. Run npm run start.
  3. Observe that the output vanishes after three seconds.
Environment
  • npm -v: 11.6.0
  • node -v: v22.18.0
  • OS Name: macOS 15.6
  • System Model Name: MacBook Pro
  • npm config:
    //localhost:4873/:_authToken = (protected)
    //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 by reproducing the behavior with the package.json script shown in the issue and running npm run start. Trace the npm run output handling to find where the final newline affects displayed output; done means script output without a trailing newline remains visible after the command exits.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.