npm / npm/cli

[BUG] npx opening the PowerShell script with the default editor instead of executing it.

Open
#3,843 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Bug cmd:exec Needs Triage Release 7.x
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
Current Behavior

I created a package containing a bunch of PowerShell scripts. In the package.json file of the package, there's such a block:

"bin": {
    "say-hello": "./hello.ps1"
}

The package is pushed to an npm registry.

In another location, I want to use the package and have a very simple way to be able to execute scripts from the package, let's say the hello.ps1 that is defined as a binary in the package. So, when I installed the package using another package.json file like this:

{
  "name": "blaa",
  "private": true,
  "version": "1.0.0",
  "devDependencies": {
    "tooling": "0.0.11"
  }
}

where tooling is the name of the package to be installed, the node_modules/.bin folder gets populated with three files:

  • say-hello
  • say-hello.cmd
  • say-hello.ps1

Now, using PowerShell in the same folder where the package.json resides, I execute npx say-hello but I get:

This program is blocked by group policy. For more information, contact your system administrator.

The computer is corporate managed and enforces a lot of policies. Looks like the say-hello.cmd file was attempted to be executed but failed. I know that I can execute PowerShell scripts. Why is npx defaulting to run the .cmd file if it can detect that the shell is PowerShell? Is it possible to configure npm/npx to execute the .ps1 file instead? Trying to run npx say-hello.ps1 command opens the script in Notepad++ in my case, instead of executing it.

Expected Behavior

npx should understand that PowerShell is the current shell and executes the say-hello.ps1 file. Or at least executes it when specifying the extension of the file, like in this command: npx say-hello.ps1.
If this is not possible, then there should be a configurable option in a .npmrc or package.json to specify which shell must be used to execute scripts.

Steps To Reproduce

No response

Environment
  • OS: Windows 10
  • Node: v14.17.0
  • npm: 7.24.2

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 with the npx invocation and the generated node_modules/.bin files on Windows 10, using the package.json bin entry and the listed Node and npm versions. Compare say-hello, say-hello.cmd, and say-hello.ps1, then determine the supported behavior or configuration that makes PowerShell execution work as requested.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs, powershell
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.