5

I'm just starting with node, and server stuff in general. I was following along with a well-reviewed youtube video and am at a loss here. I installed webpack and webpack-dev-server both globally and in my project folder. Now if I try to run webpack (typing nodejs webpack in the terminal) or webpack-dev-server, it just give me this error:

andrew@AndrewLaptop:~/Documents/mean-todo-app$ nodejs webpack

module.js:340
    throw err;
          ^
Error: Cannot find module '/home/andrew/Documents/mean-todo-app/webpack'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3

Shoudln't it be looking in mean-todo-app/node_modules/webpack instead of mean-todo-app/webpack?

Again, new to all of this so I could be missing something stupid, but I did search to no avail.

Thanks

edit: guess I could have mentioned I'm on Ubuntu if that matters

CodeNotFound
  • 22,153
  • 10
  • 68
  • 69
Andrew
  • 51
  • 1
  • 1
  • 2

4 Answers4

5

try using

npm install webpack

and do this in the root directory of your app.

Rutvij Dhotey
  • 51
  • 1
  • 2
1
var webpack = require('webpack');

you can use './webpack' only if you have something.js in the same directory if you require modules installed from third party source like npm use only require('webpack');

Kenichi Shibata
  • 148
  • 2
  • 11
1

Directly use webpack on your terminal. You don't need to refer nodejs here. Refer this documentation for executing webpack via command line as well as npm scripts: http://survivejs.com/webpack/developing-with-webpack/getting-started/#adding-a-build-shortcut

Aditya Singh
  • 15,810
  • 15
  • 45
  • 67
0

I had this problem as well. Struggled a few hours trying to figure this out. I'm on windows 10, so hopefully this will help you...

First, you need to run 2 separate processes. In Windows Power Shell, you run: node server

THEN... in another WPS, you run: webpack-dev-server

From Chrome, type in: localhost://8080

You don't want to run "node webpack-dev-server" in the second shell. That kept throwing me off.