menu

Questions & Answers

windows command not running on npm scripts

enter image description here

"scripts": {
    "start": "webpack serve",
    "watch": "webpack --watch",
    "build": "set NODE_ENV=production && webpack",
    "build-dev": "webpack",
    "clean": "Remove-Item -Recurse -Force dist"
  },

This is the output I get

PS C:\E Drive\Practice Folders\Webpack Practice Folder\New Webpack Tutorials\Swash> npm run clean

> webpack@1.0.0 clean C:\E Drive\Practice Folders\Webpack Practice Folder\New Webpack Tutorials\Swash
> Remove-Item -Recurse -Force dist

'Remove-Item' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! webpack@1.0.0 clean: `Remove-Item -Recurse -Force dist`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the webpack@1.0.0 clean script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Manjunath C\AppData\Roaming\npm-cache\_logs\2023-01-17T12_06_41_660Z-debug.log

enter image description here

Can anyone help? I am not able to find anything.

Answers(1) :

npm scripts use cmd.exe, not powershell, to execute the commands. You would need to add a powershell invocation first:

{
  "scripts": {
    "start": "webpack serve",
    "watch": "webpack --watch",
    "build": "set NODE_ENV=production && webpack",
    "build-dev": "webpack",
    "clean": "powershell \"Remove-Item -Recurse -Force dist\""
  }
}