Locally installed NPM module commands can't be found

Viewed 177

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!

1 Answers

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.

Related