[BUG] `npm run dev` result in 'rollup' is not recognized as an internal or external command
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 [email protected]
npm info using [email protected]
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
> [email protected] 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:
- clone a repo(svelte-app for example) or make a
package.jsonwith it's own script - Run 'npm run dev' or other script
- 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.
we can't change the command name because not everything passed to a script will be something that was installed by npm and will exist with a .cmd extension, so by adding it implicitly we would break a lot of workflows.
it is somewhat unusual that your command isn't running, seeing as windows supports running commands without the .cmd extension implicitly. is rollup.cmd located in your project's node_modules/.bin directory?
yes, it is. the file exists.
PS E:\picasso250\mathjsui\node_modules\.bin> ls
目录: E:\picasso250\mathjsui\node_modules\.bin
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2021/4/2 2:14 342 livereload
-a---- 2021/4/2 2:14 288 livereload.cmd
-a---- 2021/4/2 2:14 512 livereload.ps1
-a---- 2021/4/2 6:10 302 mathjs
-a---- 2021/4/2 6:10 322 mathjs.cmd
-a---- 2021/4/2 6:10 793 mathjs.ps1
-a---- 2021/4/2 2:14 308 mime
-a---- 2021/4/2 2:14 271 mime.cmd
-a---- 2021/4/2 2:14 478 mime.ps1
-a---- 2021/4/2 2:14 330 rollup
-a---- 2021/4/2 2:14 282 rollup.cmd
-a---- 2021/4/2 2:14 500 rollup.ps1
-a---- 2021/4/2 2:14 316 sirv
-a---- 2021/4/2 2:14 275 sirv.cmd
-a---- 2021/4/2 2:14 486 sirv.ps1
-a---- 2021/4/2 2:14 320 terser
-a---- 2021/4/2 2:14 277 terser.cmd
-a---- 2021/4/2 2:14 490 terser.ps1
the rollup without .cmd is the bash file, which is installed by default.
I tried cmd and powershell, they are the same on that problem.
@picasso250 does this work in v6? From our testing, we can't seem to replicate... can you also ensure you're using the latest v7 (ie. npm i -g npm)
SEE BELOW | This happened to me too. Is there a way around this?
EDIT: I forgot to install the node modules by doing npm i. I'm stupid lol
This is happened to me again