Siraj Kakeh
Siraj Kakeh

Reputation: 763

Webpack-Dev-Server keeps looking for src folder

I have a simple html page with one script added and trying to use webpack dev server to load the page, but it keeps returning this error to me ERROR in multi (webpack)-dev-server/client?http://localhost:3000 ./src Module not found: Error: Can't resolve './src' in 'C:\Users\etc\Desktop\etc' and this is my webpack.config.js

const path = require('path');
module.exports = {
  devServer: {
    contentBase: path.resolve(__dirname, 'source/index.html'),
    port: 3000
  }
}

and I'm running this command webpack-dev-server --config ./webpack.config.js

Upvotes: 3

Views: 5869

Answers (2)

Siddharth Jain
Siddharth Jain

Reputation: 880

Let me help you out of this problem : Please go to your project and try running "npm run dev" if it throws error : Like mentioned above please run below command ,

nano `package.json`

or

vi package.json

and see if it has not "dev" task inside "scripts" as below , then please see if it is in "start"

"scripts": {
"build": "webpack --config webpack/webpack.config.prod.js --colors",
"dev": "webpack-dev-server --open --config webpack/webpack.config.dev.js"
}

or

"scripts": {
"build": "webpack --config webpack/webpack.config.prod.js --colors",
"start": "webpack-dev-server --open --config webpack/webpack.config.dev.js"
}

Then run command like 

npm run dev

 or 

npm run start

 based on it. Hope it will help. Mark it as resolved if it answered query. Please suggest for improvements, appreciated! .

Upvotes: 0

Simon.Lay
Simon.Lay

Reputation: 258

In default, Webpack4 use ./src to be the enter path. If 'C:\Users\etc\Desktop\etc' doesn't include ./src, you can specify your enter path by webpack.config.js, Could you try this :

const path = require('path');
module.exports = {
  // the enter path
  entry: "YOUR APP PATH",
  devServer: {
    contentBase: path.resolve(__dirname, 'source/index.html'),
    port: 3000
  }
}

And it is easy to config, please see https://webpack.js.org/configuration/

Upvotes: 1

Related Questions