2

For any scripts that are set up in my package.json file for modules installed locally, npm says it cannot find the command.

Below is my package.json. I have already run an ‘npm install` without any issues installing the packages.

{
  "name": "app",
  "private": true,
  "dependencies": {
    "@babel/core": "^7.8.6",
    "@babel/preset-env": "^7.8.6",
    "@babel/preset-react": "^7.8.3",
    "babel-loader": "^8.0.6",
    "bootstrap": "^4.4.1",
    "jquery": "^1.9.1",
    "react": "^16.13.0",
    "react-dom": "^16.13.0",
    "react-owl-carousel": "^2.3.1",
    "react-redux": "^7.2.0",
    "react-router-dom": "^5.1.2",
    "react-slick": "^0.25.2",
    "reactstrap": "^8.4.1",
    "redux": "^4.0.5",
    "redux-logger": "^3.0.6",
    "redux-thunk": "^2.3.0",
    "slick-carousel": "^1.8.1",
    "webpack-cli": "^3.3.11"
  },
  "scripts": {
    "postinstall": "webpack",
    "start": "webpack --watch --mode=development"
  },
  "engines": {
    "node": "10.13.0",
    "npm": "6.4.1"
  },
  "devDependencies": {
    "css-loader": "^3.4.2",
    "style-loader": "^1.1.3",
    "webpack": "^4.42.0"
  }
}

When I try to run npm start from the root file, I get these errors:

sh: webpack: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! app@ start: `webpack --watch --mode=development`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the app@ start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

I have this same problem across multiple projects. If I install globally it will work, but from what I understand with webpack, that should not be necessary and is discouraged: https://webpack.js.org/guides/installation/#global-installation.

Any ideas what the trouble may be here? Thanks!

andhudhow
  • 21
  • 1
  • 3
  • Does this answer your question? [webpack command not working](https://stackoverflow.com/questions/38788166/webpack-command-not-working) – Mehdi Mar 15 '20 at 10:54
  • This question describes the way I have it set up, but the issue is that it's not working when configured that way. I've also deleted `node_modules` and `package_json.lock` and upgraded npm / node to latest version but am still hitting the same problem. This is happening for not only webpack, but anything not installed globally (only locally) that I try to use `npm run` for. – andhudhow Mar 15 '20 at 18:32

1 Answers1

0

The issue was the directory my app was located in had a / in the directory name (e.g. a/b > app > node_modules). The / is interpreted as a : and npm doesn't like that.

andhudhow
  • 21
  • 1
  • 3