Error: cannot find module "... / webpack"

I am just starting with node, and the server in general. I followed along with a well-watched YouTube video, and I don’t understand here. I installed webpack and webpack-dev server both globally and in the project folder. Now, if I try to start webpack (by typing nodejs webpack in the terminal) or webpack-dev-server, it will 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 

Shouldn't you look for mean-todo-app / node_modules / webpack instead of middle-todo-app / webpack ?

Again, new to all of this so that I might be missing out on something stupid, but I was looking to no avail.

thanks

edit: think i could mention i'm on ubuntu if that matters

+5
source share
5 answers

try using

 npm install webpack 

and do it in the root directory of your application.

+3
source
 var webpack = require('webpack'); 

you can use './webpack' only if you have something.js in the same directory if you need modules installed from a third-party source, for example, using npm requires only ("webpack");

+1
source

Use webpack on your terminal. Here you do not need to reference nodejs . See this documentation for running webpack through the command line, as well as npm scripts : http://survivejs.com/webpack/developing-with-webpack/getting-started/#adding-a-build-shortcut

+1
source

I also had this problem. They tried to understand this for several hours. I'm on windows 10, so hopefully this helps you ...

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

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

From Chrome, type: localhost: // 8080

You do not want to run "node webpack-dev-server" in the second shell. It kept throwing me away.

0
source

npm install --save-dev webpack not enough.

You also need to set the following:

 npm install --save-dev webpack-dev-server 

Also more

0
source

Source: https://habr.com/ru/post/1246372/


All Articles