1

I'm having trouble with my node.js/npm setup,

I freshly installed it via the website and it worked fine. It told me to make sure /usr/local/bin/npm has to be in my path and when I run echo $PATH it is in there, so it should be fine.

I can now install packages (tested with npm i webpack -save-dev) the installation works as expected, without any errors.

But when i run webpack all It is giving back is command not found has anyone experienced something like this before?

Jannik Lehmann
  • 468
  • 5
  • 25
  • It will be installed in your node_modules/webpack folder. You can prob run it with node_modules/.bin/webpack from your project root (btw it is --save-dev) – Sam Redway May 29 '17 at 19:56
  • Thanks for your comment! it does run with node_modules/.bin/webpack (btw it is --save-dev), still wondering why just "webpack" isn't working. – Jannik Lehmann May 29 '17 at 19:58
  • 1
    Because although npm is installed globally webpack is not (you would have to install with the -g flag for that) .. you want it local though so that you can have different versions for different projects etc. see this https://stackoverflow.com/questions/5926672/where-does-npm-install-packages?rq=1 – Sam Redway May 29 '17 at 19:59
  • but that would mean if i run 'npm i -g webpack' then 'webpack' should work, right? i just tried it, and it didn't – Jannik Lehmann May 29 '17 at 20:04
  • It should work - check that webpack is in /usr/local/bin and make sure that /usr/local/bin/ is on on your PATH ... otherwise something is broken :) – Sam Redway May 29 '17 at 20:15
  • other than the nodejs installer said, there is actually nothing at /usr/local/bin/ instead the packages are at /Users/username/.node/bin i added export PATH=$PATH:/Users/username/.node/bin to .bash_profile but it doesn't do the trick... – Jannik Lehmann May 29 '17 at 20:35

2 Answers2

2

I believe what you are looking for is a global package install. Try using

npm i -g webpack

You can get help on install with

npm help i

Claudio Viola
  • 289
  • 2
  • 5
  • He probably doesn't want to install it globally really - he wants it locally with his project. – Sam Redway May 29 '17 at 19:53
  • It is the same issue for global packages. – Jannik Lehmann May 29 '17 at 19:59
  • ok! in that case, like Sam suggested run webpack from the bin folder... if you need to use webpack from command line then you should install globally.. or use webpack from within package.json npm scripts.. and node will detect the location for you – Claudio Viola May 29 '17 at 20:01
  • i just installed globally via 'npm i -g webpack' 'webpack' command is still not found, as mentioned it works when running directly from node_modules folder – Jannik Lehmann May 29 '17 at 20:09
  • Hi Jannik, try looking at this answer https://stackoverflow.com/questions/12594541/npm-global-install-cannot-find-module?rq=1 Alternatively I also suggest to install nvm with > brew install nvm – Claudio Viola May 29 '17 at 21:35
0

Did you install node v8/npm v5?

In that case, it seems there's an open big-bug ticket on the npm repository.

Diego Ferri
  • 2,657
  • 2
  • 27
  • 35