Running webpack on Mac
<p>I have a project which uses webpack. To run webpack, I first installed node (v. 6.9.1) and npm (v. 3.10.8), then used <code>sudo npm install webpack -g</code> to install webpack globally. When I try to run webpack in the project, it says the following error:</p>

<pre><code>module.js:471
    throw err;
    ^

Error: Cannot find module 'webpack'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.&lt;anonymous&gt; (/path/to/myproj/webpack.config.js:1:77)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
</code></pre>

<p>I searched a lot online, and the best suggestion was to install it locally. I tried to install it locally, but then I got this error:</p>

<pre><code>npm ERR! not a package /path/to/myproj/webpack
npm ERR! addLocal Could not install /path/to/myproj/webpack
npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "i" "webpack"
npm ERR! node v6.9.1
npm ERR! npm  v3.10.8
npm ERR! path /var/folders/zk/vhg127bn2b1g2vg4mfb941yr0000gn/T/npm-14256-797b3412/unpack-5c7f7eb6/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open

npm ERR! enoent ENOENT: no such file or directory, open '/var/folders/zk/vhg127bn2b1g2vg4mfb941yr0000gn/T/npm-14256-797b3412/unpack-5c7f7eb6/package.json'
npm ERR! enoent ENOENT: no such file or directory, open '/var/folders/zk/vhg127bn2b1g2vg4mfb941yr0000gn/T/npm-14256-797b3412/unpack-5c7f7eb6/package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! Please include the following file with any support request:
npm ERR!     /path/to/myproj/npm-debug.log
</code></pre>

<p>So I thought maybe I have to uninstall webpack first. I did so using <code>sudo npm remove webpack -g</code>, and tried to install it locally, but still the same error. This time even installing it globally would generate the same error. So I could not install webpack unless I reinstalled node.</p>

<p>So why originally the webpack package was not found? how I can install it to get it to work?</p>

<p>Thanks</p>