npm / npm/cli

[BUG] `npm run dev` result in 'rollup' is not recognized as an internal or external command

Open
#3,018 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug platform:windows Release 7.x
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

Current Behavior:

when run npm run dev

E:\picasso250\mathjsui>npm run dev --verbose
npm verb cli [
npm verb cli   'E:\\Program Files\\nodejs\\node.exe',
npm verb cli   'C:\\Users\\xiaochi\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
npm verb cli   'run',
npm verb cli   'dev',
npm verb cli   '--verbose'
npm verb cli ]
npm info using npm@7.8.0
npm info using node@v14.16.0
npm timing npm:load:whichnode Completed in 2ms
npm timing config:load:defaults Completed in 2ms
npm timing config:load:file:C:\Users\xiaochi\AppData\Roaming\npm\node_modules\npm\npmrc Completed in 1ms
npm timing config:load:builtin Completed in 1ms
npm timing config:load:cli Completed in 2ms
npm timing config:load:env Completed in 0ms
npm timing config:load:file:E:\picasso250\mathjsui\.npmrc Completed in 0ms
npm timing config:load:project Completed in 1ms
npm timing config:load:file:C:\Users\xiaochi\.npmrc Completed in 1ms
npm timing config:load:user Completed in 1ms
npm timing config:load:file:C:\Users\xiaochi\AppData\Roaming\npm\etc\npmrc Completed in 0ms
npm timing config:load:global Completed in 0ms
npm timing config:load:validate Completed in 2ms
npm timing config:load:setEnvs Completed in 1ms
npm timing config:load Completed in 10ms
npm timing npm:load:configload Completed in 11ms
npm timing npm:load:setTitle Completed in 0ms
npm timing npm:load:setupLog Completed in 2ms
npm timing npm:load:cleanupLog Completed in 2ms
npm timing npm:load:configScope Completed in 0ms
npm timing npm:load:projectScope Completed in 1ms
npm timing npm:load Completed in 30ms
npm timing config:load:flatten Completed in 2ms
[..................] | : timing config:load:flatten Completed in 2ms
> svelte-app@1.0.0 dev
> rollup -c -w

'rollup' is not recognized as an internal or external command,
operable program or batch file.
npm timing command:run-script Completed in 24ms
npm verb exit 1
npm timing npm Completed in 268ms
npm verb code 1

or if you are Chinese, it shows:

'rollup' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
Expected Behavior:

run npm run dev

it run the script without complain.

Steps To Reproduce:
  1. clone a repo(svelte-app for example) or make a package.json with it's own script
  2. Run 'npm run dev' or other script
  3. See error
Environment:
  • OS: Win10
  • Node: 14.16.0
  • npm: 7.8.0
reason

it is not about rollup, it's about npm sending wrong args to windows cmd

currently, npm do this:

spawn('cmd', [
    "/d /s /c",
    "rollup -c -w",
], options);

windows complains.

but if you send this:

spawn('cmd', [
    "/d /s /c",
    "rollup.cmd", "-c", "-w", // add '.cmd' 
],options);

windows will find it in './node_modules/.bin'

a fix

replace node_modules\@npmcli\run-script\lib\make-spawn-args.js:18 with

  // const args = isCmd ? ['/d', '/s', '/c', cmd] : ['-c', cmd]
  const cmdArray = cmd.split(" ")
  if (isCmd) {
    if (cmdArray.length > 0) {
      const cmdProg = cmdArray[0]
      if (/^\w+$/.test(cmdProg)) {
        cmdArray[0] = cmdProg + ".cmd"
      }
    }
  }
  const args = isCmd ? ['/d', '/s', '/c',].concat(cmdArray) : ['-c', cmd]

of course it is not a "correct" fix, but it works for most scripts.

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 at node_modules@npmcli\run-script\lib\make-spawn-args.js:18 and reproduce the failure on Windows with a local .bin command invoked through npm run dev. Compare the generated cmd arguments with the reported examples; done means the script locates the Windows command and runs without the 'not recognized' error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.