-
Notifications
You must be signed in to change notification settings - Fork 612
A Node.js application written in ESM uses CommonJS distribution of the SDK #2900
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
Comments
This one should actually be pretty easy to fix, assuming es doesn't assume browser: the current package.json files have:
which was the bundler convention, but the native Node ESM support ignores
Note that this will enforce encapsulation, so anybody doing something like |
I am trying to use aws-cdk with the nodejs function. This bundles my lambda code with esbuild. |
@tenjaa Can you create a new bug report? |
Changes needed if (and when) we publish Node.js (ESM) artifacts in future.
The naming is picked up from suggestions in #3531 |
Node.js official docs recommend two solutions for dual-packaging: An ESM wrapper or Isolate State. On quick look, the ESM wrapper appears to be a better solution as:
If we decide to use ESM Wrapper, the package.json would be as follows:
|
Note that those recommendations are largely for the case where you have globalish state that could cause problems when there are multiple versions bundled. So far as I've seen messing around in the internals so far, this repo mostly just has caches and the like, nothing like the v2 global config. That said, so long as you don't need to manage the wrappers, that should work fine. I've had lots of headaches managing multiple builds. The real question though, is if you actually need a commonjs build at all at this point? You're either running directly in node or though a bundler, in both cases you have native ESM support in their supported versions: node v12.22.0 stabilized esm support, and that's the oldest supported version. |
Ah, of course, you can't |
Yup, it's important to use either .cjs or .mjs file extensions, otherwise one of the bundles will be broken (depending on whether the library's package.json has a |
Closing this in favor of #3223 |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread. |
Is your feature request related to a problem? Please describe.
A Node.js application written in ESM uses CommonJS distribution of the SDK.
Example code:
node_modules/@aws-sdk/property-provider/dist-cjs/chain.js
It uses distribution in
dist-cjs
and not indist-es
Screen recording
StepThroughMJS.mov
Describe the solution you'd like
The Node.js application written in ESM should use distribution indist-es
The Node.js application written in ESM should use folder in
dist-node-esm
(UPDATE April 2022)Describe alternatives you've considered
A different distribution for Node.js ESM, which can be take up while implementing Node.js specific distributions in #2889 to avoid increasing install size.
Additional context
The text was updated successfully, but these errors were encountered: