Windows 10: npm opens vscode instead of running postinstall script on

What I Wanted to Do

Install acme-v2.

npm install acme-v2

What Happened Instead

The install froze and opened vscode to the file listed as package.main.

Reproduction Steps

npm install acme-v2

Note that the package installs and runs the postinstall script as expected on all other platforms. The postinstall script just prints a message to the screen, nothing fancy.

package.json:

{ "name": "acme-v2",
  "main": "node.js",
  ...
  "scripts": {
    "postinstall": "node scripts/postinstall"
  }
}

Details

I think this may somehow be due to the name of package.main being node.js and perhaps the way (cmd-shim)[https://github.com/npm/cmd-shim] sets up the path and executable extensions, prioritizing .js files over .exe

Platform Info

Windows 10

$ npm --versions

Can't copy/paste from my Windows 10 vm... but it's npm 6.11.3, I just updated for the report.

node 10.16.0

$ node -p process.platform

win 32

I think this is probably less about cmd-shim, and more about cmd itself. . is always prioritized over the Path environment variable, and .JS is typically in the PATHEXT environment variable. So node will resolve to node.js if a ./node.js file exists, and then open it with the default program for executing .js files, which in your case is VSCode.

Confirmation of this theory: Open up a command prompt and type echo %PATHEXT%. See if it includes ;.JS; in there.

Workaround (assuming theory is correct): remove .JS from your PATHEXT environment variable in your system settings.

Solution: npm could remove .JS from the PATHEXT when running lifecycle scripts. That’s probably a good idea, and it’s unlikely to break anyone’s current workflow, but it technically could be considered a breaking change. I’m open to it, but we should put it through an rfc at https://github.com/npm/rfcs

Can’t copy/paste from my Windows 10 vm… but it’s npm 6.11.3, I just updated for the report.

You can, actually! Alt-Space, E, K, then select with the mouse, and hit Enter to copy it.

You can, actually! Alt-Space, E, K, then select with the mouse, and hit Enter to copy it.

I meant that I’m using Parallels and I have BetterTouchTool installed for my key mappings, so I literally can’t copy/paste.

I think this is probably less about cmd-shim, and more about cmd itself.

I see what you’re saying. I thought that .js had been added by cmd-shim (based on something I saw in one of the templates during my last bug report), but I forgot that it exists for Windows Scripting Host.

Thanks so much for checking this out.

You can also click the menu in the upper left of the cmd window, and do Edit>Mark, select text, the Edit>Copy.