Fix Ctrl C behavior on Windows


(Mike Mac Cana) #1

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:

(Kat Marchán) #2

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

(system) closed #3

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.