New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
this.importModule broken in esm packages #18023
Comments
Honestly there are no problems here, you set |
The problem is not about
there is a nextjs branch in the reproduction repository - there banner.ts is using https://github.com/jantimon/reproduction-webpack-import-module-bug/blob/nextjs/app/banner.ts |
In the case of nextjs you have technically this should work: config.externals.unshift({
"cowsay": "node-commonjs cowsay"
}) It's better to create this question in nextjs repo |
renaming I am not sure what I could see inside the next folder this is the
|
I mean you will see files in ESM format, please open an issue in the nextjs repo, webpack works fine here |
Also looks like there is the nextjs bug, because using:
Still generates |
Thanks for your help and time @alexander-akait! I'll try to investigate further to find out how |
This issue had no activity for at least three months. It's subject to automatic issue closing if there is no activity in the next 15 days. |
Bug report
What is the current behavior?
I am using the Webpack loader API
this.importModule
which invokesvm.runInThisContext
to execute the module code.However, as soon as the
package.json
file includes"type": "module"
vm.runInThisContext
does not have access torequire
andmodule
anymore:If the current behavior is a bug, please provide the steps to reproduce.
Here is a reproduction:
https://github.com/jantimon/reproduction-webpack-import-module-bug
webpack.config.js
./loader.cjs
./banner.js
What is the expected behavior?
module
andrequire
should be available inwebpack/lib/javascript/JavascriptModulesPlugin.js
The following change would fix the bug:
This fix would requires Node 12:
The 'module.createRequire' is not supported until Node.js 12.2.0
Other relevant information:
webpack version: 5.90.0
Node.js version: 20.9.0
In Next.JS the problem exists also for typescript files even for ESM syntax:
https://github.com/jantimon/reproduction-webpack-import-module-bug/tree/nextjs
The text was updated successfully, but these errors were encountered: