-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Labels
Description
Bug Description
I tried the configuration module.parser.javascript.createRequire: true along with module.parser.javascript.commonjs: true. When ES module depends to local CommonJS modules (.cjs or etc.) by using createRequire() - require(), bundling will performed correctly if non-pure ES module such as .mts uses CommonJS, but performed with error if pure ES module (without transpilation) such as .mjs uses CommonJS.
Link to Minimal Reproduction and step to reproduce
https://github.com/jet2jet/webpack-create-require-test
Steps:
- Run
npm installornpm ci - Run
npm run build
Expected Behavior
Bundling process works correctly (with no errors)
Actual Behavior
An error is reported for requiring CommonJS from .mjs with message such as: Module not found: Error: Can't resolve 'module' in '/path/to/project/src'
- In the above repository, two entry points are specified:
src/ts.mtsandsrc/js.mjs, andsrc/foo.cjsis imported fromsrc/ts.mtsandsrc/js.mjs. Forsrc/ts.mts, bundling process works correctly as expected, butsrc.js.mjsnot.
Environment
System:
OS: Linux 6.6 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
Memory: 6.99 GB / 7.58 GB
Binaries:
Node: 20.19.3 - /home/user/.asdf/installs/nodejs/v20.19.3/bin/node
npm: 11.5.1 - /home/user/.asdf/installs/nodejs/v20.19.3/bin/npm
pnpm: 8.7.1 - /home/user/.local/share/pnpm/pnpm
Packages:
ts-loader: ^9.5.4 => 9.5.4
webpack: ^5.105.2 => 5.105.2
webpack-cli: ^6.0.1 => 6.0.1Is this a regression?
None
Last Working Version
No response
Additional Context
No response
Reactions are currently unavailable