webpack@4 – ERROR in TypeError: __webpack_require__(…) is not a function

What is the current behavior?
I’m trying to migrate from webpack@3 to webpack@4 with a simple config (https://github.com/damianobarbati/yarsk/blob/master/config/webpack.config.js) but I get:

ERROR in   TypeError: __webpack_require__(...) is not a function
  - es6.regexp.replace.js?:2 eval
    [.]/[core-js]/modules/es6.regexp.replace.js?:2:90

The bundle analyzer shows that full lodash-es is included into the bundle and no tree shaking is happening.

If the current behavior is a bug, please provide the steps to reproduce.
Here the full repro: https://github.com/damianobarbati/yarsk

Instructions in the README.
Basically just:

  • git clone https://github.com/damianobarbati/yarsk
  • yarn install
  • npm install -g pm2
  • yarn build:dev

Versions:

"devDependencies": {
    "@babel/core": "^7.0.0-beta.40",
    "@babel/polyfill": "^7.0.0-beta.40",
    "@babel/preset-env": "^7.0.0-beta.40",
    "@babel/preset-react": "^7.0.0-beta.40",
    "@babel/preset-stage-0": "7.0.0-beta.40",
    "babel-eslint": "^8.2.1",
    "babel-jest": "^22.4.0",
    "babel-loader": "^8.0.0-beta.0",
    "case-sensitive-paths-webpack-plugin": "^2.1.1",
    "clean-webpack-plugin": "^0.1.18",
    "compression-webpack-plugin": "^1.1.7",
    "eslint": "^4.18.0",
    "eslint-loader": "^1.9.0",
    "eslint-plugin-import": "^2.8.0",
    "eslint-plugin-jest": "^21.12.2",
    "eslint-plugin-react": "^7.7.0",
    "file-loader": "^1.1.8",
    "html-webpack-plugin": "webpack-contrib/html-webpack-plugin",
    "img-loader": "^2.0.1",
    "jest": "^22.4.0",
    "lodash-es": "^4.17.5",
    "open-browser-webpack-plugin": "^0.0.5",
    "url-loader": "^0.6.2",
    "webpack": "^4.0.0-beta.2",
    "webpack-bundle-analyzer": "^2.10.0",
    "webpack-cli": "^2.0.6",
    "webpack-notifier": "^1.5.1"
}

Author: Fantashit

3 thoughts on “webpack@4 – ERROR in TypeError: __webpack_require__(…) is not a function

  1. If you have to exclude node_modules/, how do you get babel to polyfill/transform code in 3rd party code?

  2. Sorry for hijacking this issue, but I ran into something similar when trying to run my node_modules through babel as well (with a simplified config, similar to CRA), and this is the only issue I can find that’s even slightly related. The issue seems to be core-js related. Am I right in thinking this is also going wrong in html-webpack-plugin?

    Note: I do have the sourceType set to unambiguous.

    ERROR in   Error: webpack-internal:///./node_modules/core-js-pure/modules/es.array.is-array.js:7
      $({
      ^
      TypeError: $ is not a function
    
      - es.array.is-array.js:7 eval
        [.]/[core-js-pure]/modules/es.array.is-array.js:7:1
    
      - index.html:1822 Object../node_modules/core-js-pure/modules/es.array.is-array.js
        c:/Code/app/public/index.html:1822:1
    
      - index.html:687 __webpack_require__
        c:/Code/app/public/index.html:687:30
    
      - index.html:61 fn
        c:/Code/app/public/index.html:61:20
    
      - is-array.js:1 eval
        [.]/[core-js-pure]/es/array/is-array.js:1:1
    
      - index.html:951 Object../node_modules/core-js-pure/es/array/is-array.js
        c:/Code/app/public/index.html:951:1
    
      - index.html:687 __webpack_require__
        c:/Code/app/public/index.html:687:30
    
      - index.html:61 fn
        c:/Code/app/public/index.html:61:20
    
      - is-array.js:1 eval
        [.]/[core-js-pure]/stable/array/is-array.js:1:18
    
      - index.html:2086 Object../node_modules/core-js-pure/stable/array/is-array.js
        c:/Code/app/public/index.html:2086:1
    

Comments are closed.