npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

Fix Ctrl C behavior on Windows

npm’s Ctrl C behavior is broken on Windows:

$ npm run deploy
^CTerminate batch job (Y/N)? ls bi^C^C
Terminate batch job (Y/N)? ^C
Terminate batch job (Y/N)? ^C
Terminate batch job (Y/N)? ^C

This is because npm uses CMD, which is no longer maintained. Adding an npm.ps1 per below will fix the error for anyone using Window’s default shell, and allow anyone still using cmd to still use npm.cmd and have the bad behavior.

function Get-ScriptDirectory {

$Invocation = (Get-Variable MyInvocation -Scope 1).Value

Split-Path $Invocation.MyCommand.Path

}

node "$(Get-ScriptDirectory)/npm.js" $args

The script above works with Windows 7 upwards (hence Get-ScriptDirectory, which has an inbuilt replacement on new Windows versions).

Yarn fixed this recently too: https://github.com/yarnpkg/yarn/issues/6092


I believe @bterlson is working on something regarding this, so I’m mostly just working for that.