user1579234
user1579234

Reputation: 501

Webpack 4: ERROR in Entry module not found: Error: Can't resolve './src'

This is a duplicate question but I want to use custom entry instead of default to webpack 4 entry as been suggested in the post Webpack 4: Error in entry

webpack.dev.config.js:

import path from 'path';

export default {
  mode: 'development',
  entry: [
    'babel-polyfill',
    './app/components/index.js'
  ],
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  },
  module: {
    rules: [
      { test: /\.js$/, exclude: /node_modules/, use: 'babel-loader' }
    ]
  }
};

Project Structure

The following errors are shown when running webpack-wd

Insufficient number of arguments or no entry found. Alternatively, run 'webpack(-cli) --help' for usage info.

ERROR in Entry module not found: Error: Can't resolve './src' in 'C:\Patient_Check_In'

Upvotes: 4

Views: 9635

Answers (1)

pldg
pldg

Reputation: 2588

Use commonJS module syntax for webpack configuration:

webpack.config.js

const path = require('path');

module.exports = {
  mode: 'development',
  entry: [
    'babel-polyfill',
    './app/components/index.js'
  ],
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: 'babel-loader'
      }
    ]
  }
}

package.json

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "webpack.config.js",
  "scripts": {
    "build": "webpack"
  },
  "author": "",
  "license": "MIT",
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.5",
    "babel-preset-env": "^1.7.0",
    "webpack": "^4.16.5",
    "webpack-cli": "^3.1.0"
  },
  "dependencies": {
    "babel-polyfill": "^6.26.0"
  }
}

app/compontens/index.js

console.log('hello!');

If you run webpack a file called bundle.js is generated in the dist folder, that file contains all babel pollyfills, plus webpack runtime, plus your app (in this case a simple console.log statement). If you want you can set a specific babel configuration.

Upvotes: 2

Related Questions