0

I am following this tutorial - https://www.youtube.com/watch?v=JdGnYNtuEtE

I installed webpack locally

npm i -D webpack

I also installed it globally:

enter image description here

'npm i -g webpack'

It installed just fine.

My package.json file:

{
  "name": "webpack-starter",
  "version": "1.0.0",
  "description": "Webpack starter project",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "webpack": "^3.8.1"
  }
}

The next command he issues is:

webpack ./src/app.js ./dist/app.bundle

It worked in the videos but I am getting the error:

-bash: webpack: command not found

Why is this happening? Not sure I understand why it isn't working.

Morgan Allen
  • 3,291
  • 8
  • 62
  • 86
  • Read that linked duplicate. You are running into the same issue. You are not globally installing with `npm -g i webpack`. – zero298 Oct 24 '17 at 19:12
  • I did it globally as well. Still getting the issue. – Morgan Allen Oct 24 '17 at 19:29
  • OK, now, is your node install (looks like it's through brew) in your `$PATH`? Check by running `echo $PATH` and seeing if something like `/usr/local/Cellar/node/7.9.0/libexec/npm/lib/node_modules/` is listed. Look for anything related to `npm_modules` in path. That was another thing that that answer talks about. – zero298 Oct 24 '17 at 19:36
  • I read that is a security flaw. Is that true? – Morgan Allen Oct 24 '17 at 19:41
  • Cite the source that says that. If you don't have the directory that contains the webpack binary in your `$PATH`, you can't use `webpack` from the CLI. You'll have to do what one of the (now deleted) answers said and add `webpack` to your package.json's `scripts` list and run it through there as a package level dependency instead of a global install. – zero298 Oct 24 '17 at 19:43
  • I think I saw it in the comment section of someone who suggested something similar...i'll find it. – Morgan Allen Oct 24 '17 at 19:45
  • https://stackoverflow.com/questions/9679932/how-to-use-package-installed-locally-in-node-modules/9683472#9683472 – Morgan Allen Oct 24 '17 at 19:46
  • I ended up doing the second option, adding it to a script and npm run build – Morgan Allen Oct 24 '17 at 19:49
  • You could try one of the other [listed answers](https://stackoverflow.com/a/45164863/691711), `npx` which ships with npm > 5.2 which checks for package level dependencies before checking path which avoids the security concern. – zero298 Oct 24 '17 at 19:51
  • Try rehashing your environment variables to reload your path. https://superuser.com/questions/490983/how-to-rehash-executables-in-path-with-bash#490984 – Chloe Apr 02 '18 at 15:21

1 Answers1

0

Try to install webpack globally by typing npm install webpack --global if you want to run it directly via webpack command.

WutchZone
  • 154
  • 1
  • 3
  • 13