-
-
Notifications
You must be signed in to change notification settings - Fork 123
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
Dynamic import()
in a CJS file can execute a module twice
#499
Comments
This is definitely unexpected. What's happening is the first import statement gets converted to So the first and second files are technically different modules, where the first one is dynamically derived on demand. This is a technical limitation but it will be resolved once nodejs/node#51977 lands |
I understand that you keep the dynamic import, but since it’s using Even waiting for nodejs/node#51977 would not really resolve the issue since this patch does not support requiring modules with top level async in them. Replacing the |
I'm not sure, but feel free to give it a tackle. I'd be happy to review the PR! |
Acknowledgements
Minimal reproduction URL
https://stackblitz.com/edit/stackblitz-starters-hfn7ts
Version
4.7.1
Node.js version
18.18.0 and 20.11.0
Package manager
npm
Operating system
Linux
Problem & expected behavior (under 200 words)
I’m in the process of migrating an app from
CJS
toESM
. This app contains some dynamic imports. The files dynamically imported are in part all the mongoose models to collect data on them and to basic checks. As soon as I started changing the extension of some models from.ts
to.mts
I had issues with mongoose reporting that I'm trying to register the same model twice. I made a simple repro in the provided stackblitz.You have 2 files in my minimun repro. One
works.mts
and onebugs.ts
. They both basically contain the same code. Only the extension changes. It should execute themodule.mts
file alongside them only once. But in one case it is executed twice.Contributions
The text was updated successfully, but these errors were encountered: