-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
chore: add sample on how to use esm on cjs #14051
base: master
Are you sure you want to change the base?
Conversation
9ef810c
to
0dafaaa
Compare
Pull Request Test Coverage Report for Build 623fb4ab-f46c-4d69-b132-79d31a3d20bdDetails
💛 - Coveralls |
CI is failing because it's using node16 while the new sample will only work on node18 because of Jest ESM support: not sure what I can do as we do want to test against node16 as well to ensure that nestjs is still compatible with it I guess. I'll see if could ignore that sample when nodejs version is 16 |
Would it be possible to make this work for nestjs + swc as well? |
ea3fef0
to
8e777ad
Compare
@Apidcloud it's just the same as sample 34 or 35. I just tested it. |
I remember that my issue a couple of weeks ago with SWC was the dynamic imports (i.e., the node require module experimental flag also worked for me). But from the example you provided, is this the way to make it work with a dynamic import instead of relying on the experimental flag? They already unflagged it on Node 23 and might backport it to Node 22 on a minor, so it's not a big deal, I guess.
|
@Apidcloud from what I tested, yes. Having a function like |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
no examples on how to use ESM-only packages with nestjs (CJS apps), although not directly related with nestjs
What is the new behavior?
this is a first stage to address the issue nestjs/docs.nestjs.com#3093
After creating that new page, I'll mention about these samples as an working examples on three ways to use ESM-only packages in our CJS projects: importing the package when needed or declaring it like a custom provider, or using the
--experimental-require-module
nodejs flagAbout the sample 35: I'm not sure on keeping a dedicate sample because it is just a matter of using a nodejs flag. And we can mention this in the docs. This flags has few gotchas (see https://nodejs.medium.com/announcing-a-new-experimental-modules-1be8d2d6c2ff)
Does this PR introduce a breaking change?