Skip to content

__webpack_require__(...) is not a function with babel-loader #1223

@mogelbrod

Description

@mogelbrod

Expected behaviour

Using babel-loader and html-webpack-plugin shouldn't require any special configuration.

Current behaviour

Webpack throws the following error with a minimal repro using only webpack, babel-loader and html-webpack-plugin:

TypeError: __webpack_require__(...) is not a function
  - index.html:1718 Module../node_modules/webpack/buildin/harmony-module.js

Environment

Node.js v12.1.0
darwin 18.6.0
npm 6.9.0
[email protected] .../webpack-issue
└── [email protected]
[email protected] .../webpack-issue
└── [email protected].

Config

const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = function(env) {
  return {
    mode: 'development',

    entry: {
      app: './index.js',
    },

    output: {
      path: __dirname + '/dist',
      filename: 'index.js',
      publicPath: '/'
    },

    module: {
      rules: [
        {
          test: /\.js$/,
          loader: 'babel-loader',
        },
      ],
    },

    plugins: [
      new HtmlWebpackPlugin({
        template: 'index.html',
      }),
    ],

    bail: true,

    devServer: {
      contentBase: 'public',
      inline: true,
      port: 3000,
    }
  }
}

Relevant Links

Repository with minimal repro repository

Possibly related:

Workaround

diff --git a/webpack.config.js b/webpack.config.js
index 34e17ce..8bf6b03 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -20,6 +20,9 @@ module.exports = function(env) {
       rules: [
         {
           test: /\.js$/,
+          exclude: [
+            /node_modules\/(webpack|html-webpack-plugin)\//,
+          ],
           loader: 'babel-loader',
         },
       ],

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions