1
votes

Im trying to run the following command,

webpack-dev-server

but it throws the following error,

>  at Object.Module._extensions..js
> (internal/modules/cjs/loader.js:785:10) at Module.load
> (internal/modules/cjs/loader.js:641:32) at Function.Module._load
> (internal/modules/cjs/loader.js:556:12) at Function.Module.runMain
> (internal/modules/cjs/loader.js:837:10) { 
    code: 'MODULE_NOT_FOUND', requireStack: [
> '<path_to_project>\\node_modules\\webpack-dev-server\\bin\\webpack-dev-server.js'  ] 
> }
4
thaaanks, now it works. but can you explain to me why i had to run npm/yarn install? if before this, i installed the dependencyLaura Beatris

4 Answers

1
votes

I faced a similar issue too, what I was doing was I miss spelt a property in my webpack.config.js which is

module.exports = {
  entry: "./src/index.js",
  output: {
    path: path.resolve(__dirname, "dist/assets"),
    filename: "bundle.js",
  },
  devServer: {
    contentBase: path.resolve(__dirname, "dist"),
    publicPath: "/assets", //should provide the path of the served js , img , etc...
  },
};

in the above code I wrongly spet contentBase as contenBase, when I changed it back, it worked well!! You should be looking out for similar issues too

4
votes

For me helped to run "webpack-dev-server" after I add the script to "package.json" as "start": "webpack serve --open"

2
votes

The problem is that you haven't run yarn/npm install.

2
votes

I found an easy solution to this. Change the "start" script in your package.json to the following instead:

"start": "webpack serve --config webpack.config.js --open"

where webpack.config.js is your webpack config file.

I hope it works!