4

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'

user1579234
  • 501
  • 5
  • 15

1 Answers1

2

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.

pldg
  • 2,427
  • 3
  • 22
  • 37
  • It works. I edited my answer to show you the rest of my test repository. Try it yourself. You probably have some other code in your configuration that create that bug. – pldg Aug 14 '18 at 14:46
  • By default webpack finds the config file 'webpack.config.js'. If you specify custom config file, like the one provided in this issue, you can run: 'webpack --config webpack.dev.config.js' – user1579234 Aug 19 '18 at 18:30
  • You are right. I didn't notice in your screenshot that you use a different naming for the default webpack config. Anyway as good practice I suggest you to use the default config name and import other configs (based on your environment) inside it. If you want to learn more this guide may help: https://survivejs.com/webpack/developing/composing-configuration/ – pldg Aug 19 '18 at 18:58
  • This got me closer. Still need to resolve node_modules for some reason. Thanks mate! – Urasquirrel Jul 10 '19 at 18:58