Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Error around nested __webpack_require__ #20511

@ej612

Description

@ej612

Bug Description

Hi there!

Since 5.103.0, I'm getting the following error:

Chrome 144.0.0.0 (Windows 10) ERROR
  Uncaught TypeError: __webpack_modules__[moduleId] is not a function
  at webpack://my-little-project/./node_modules/@jest/expect-utils/build/index.js?:692:41

  TypeError: __webpack_modules__[moduleId] is not a function
      at __nested_webpack_require_24761__ (webpack://my-little-project/./node_modules/@jest/expect-utils/build/index.js?:692:41)
      at ./src/utils.ts (webpack://my-little-project/./node_modules/@jest/expect-utils/build/index.js?:321:16)
      at __nested_webpack_require_24761__ (webpack://my-little-project/./node_modules/@jest/expect-utils/build/index.js?:692:41)
      at ./src/index.ts (webpack://my-little-project/./node_modules/@jest/expect-utils/build/index.js?:90:14)
      at __nested_webpack_require_24761__ (webpack://my-little-project/./node_modules/@jest/expect-utils/build/index.js?:692:41)
      at eval (webpack://my-little-project/./node_modules/@jest/expect-utils/build/index.js?:703:44)
      at eval (webpack://my-little-project/./node_modules/@jest/expect-utils/build/index.js?:706:12)
      at ./node_modules/@jest/expect-utils/build/index.js (out/r426686/commons.js:379:1)
      at __webpack_require__ (out/r426686/runtime.js:31:42)
      at eval (webpack://my-little-project/./node_modules/@jest/expect-utils/build/index.mjs?:19:67)

I have tried the most recent version 5.105.2, and the error persists. I believe it has something to do with this change mentioned in the 5.103.0 changelog:

Rename single nested __webpack_export__ and __webpack_require__ in already bundled code

Relevant commit

This seems to cause problems with a couple of jest packages, e.g. @jest/expect-utils, which redefine __webpack_require__. Example:

The error seems to happen on line 321:

321 var _getType = require("@jest/get-type");
322 var _immutableUtils = __webpack_require__("./src/immutableUtils.ts");
323 var _jasmineUtils = __webpack_require__("./src/jasmineUtils.ts");

We can see that we're calling the redefined function on lines 322 & 323, but we seem to want to call webpack's original function on line 321, since __webpack_modules__ of the redefined function doesn't contain an entry for @jest/get-type. This is confirmed in the debugger:

Image

The problem is that on webpack >= 5.103, the function that is called on line 321 is the redefined function, instead of the original function. If I rename the redefined function to abc123, I no longer have the error.

My understanding of all this is rather limited. Is this a bug in webpack or in jest? Any help is appreciated. Thank you very much in advance!

Edit: These are the relevant lines:

When I have the error:

Image

After renaming the locally declared function to abc123:

Image

Environment

System:
    OS: Windows 11 10.0.26200
    CPU: (22) x64 Intel(R) Core(TM) Ultra 9 185H
    Memory: 38.61 GB / 63.43 GB
  Binaries:
    Node: 22.15.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.22 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 10.9.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 144.0.7559.133
    Edge: Chromium (143.0.3650.96)
    Firefox: 147.0.4 - C:\Program Files\Mozilla Firefox\firefox.exe
  Monorepos:
    Yarn Workspaces: 1.22.22
    Lerna: 5.1.8
  Packages:
    babel-loader: 10.0.0 => 10.0.0
    coverage-istanbul-loader: 3.0.5 => 3.0.5
    html-webpack-plugin: 5.6.6 => 5.6.6
    karma-webpack: 5.0.1 => 5.0.1
    karma-webpack-preprocessor: 1.0.1 => 1.0.1
    ts-loader: 9.5.4 => 9.5.4
    webpack: 5.103.0 => 5.103.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions