[BUG] *.CMD shims don't work when they are in paths containing shell metachars

Open
#45 6 comments 7 reactions 0 assignees View on GitHub

@ashrafiucse is already working on this.

Since Sep 12, 2026.

  • #53 by @Timsonrobl — closed without merging
  • #188 by @the-can-of-soup — closed without merging
  • #189 by @ashrafiucse — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
javascript
Domain
cli

Research direction

Start by locating the code that generates the *.CMD shims and reproduce the reported Windows case with an npm prefix or package path containing '&'. Verify the generated command runs successfully for packages with a bin entry, including both global installation and local npm-run scenarios.

Written by the indexing model from the issue text.

Description

What / Why

Generated *.CMD files are unable to start correctly when the path to the CMD file contains certain characters.

When

  • Whenever the path contains a cmd.exe shell metacharacter (such as &).

Where

  • Any package with a "bin" entry.

How

Current Behavior
  • The shell metacharacters are parsed by the shell instead of the full argument being passed into node. With my npm prefix set to "C:/test(n&pm)" and after installing the mkdirp package globally, I see the following error when attempting to run "mkdirp" in cmd.exe.
'pm)\' is not recognized as an internal or external command,
operable program or batch file.
internal/modules/cjs/loader.js:969
    throw err;
    ^

Error: Cannot find module 'C:\test(n\node_modules\mkdirp\bin\cmd.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:17)
    at Function.Module._load (internal/modules/cjs/loader.js:859:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
Steps to Reproduce
  • Orchestrate any scenario in which the .CMD files will be generated under a path containing "&" character (in theory the other shell metacharacters would also be problematic, see references for an article on windows command line escaping).

Two scenarios come to mind.

Scenario 1: Set NPM Prefix to New Path
  1. Set npm prefix to "C:/test(n&pm)"
  2. Globally install mkdirp (or any other binary package).
  3. Make sure "C:/test(n&pm)" is in your PATH.
  4. Attempt to run "mkdirp" (or whatever you installed).
Scenario 2: Local Dependencies
  1. Create an npm package in a folder like "C:/test(n&pm)/package"
  2. Install a local dependency which has a "bin" entry (like "mkdirp")
  3. Add a script to package.json which attempts to run the dependency's bin (like "trymkdir": "mkdirp mytestfolder")
  4. Attempt to run your script: npm run trymkdir
Expected Behavior
  • The .CMD files should be able to run without getting tripped up by shell metacharacters in the path.

Who

  • n/a

References

Dominant language
JavaScript
Stars
81
Forks
51
PR merge metrics
No merged PRs in 30d

Getting set up

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.

More from npm/cmd-shim

All issues in npm/cmd-shim

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.