A Node.js application written in ESM uses CommonJS distribution of the SDK
See original GitHub issueIs your feature request related to a problem? Please describe.
A Node.js application written in ESM uses CommonJS distribution of the SDK.
Example code:
// index.mjs
import { DynamoDB } from "@aws-sdk/client-dynamodb";
const client = new DynamoDB({});
await client.listTables({});
- In VSCode, add a breakpoint on the line which calls listTables.
- Click on “Run and Debug” in the Debugging View to start debugging.
- The debug session will break at listTables.
- Click on “Step Into” debug action.
- Note that debug session steps into
node_modules/@aws-sdk/property-provider/dist-cjs/chain.js
It uses distribution in dist-cjs
and not in dist-es
Screen recording
Describe the solution you’d like
The Node.js application written in ESM should use distribution in
The Node.js application written in ESM should use folder in dist-es
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 https://github.com/aws/aws-sdk-js-v3/issues/2889 to avoid increasing install size.
Additional context
- Debugging in VSCode https://code.visualstudio.com/docs/editor/debugging
- Conditional Exports in Node.js https://nodejs.org/api/packages.html#packages_conditional_exports
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:10 (7 by maintainers)
Top Results From Across the Web
CommonJS modules | Node.js v19.3.0 Documentation
CommonJS modules are the original way to package JavaScript code for Node.js. Node.js also supports the ECMAScript modules standard used by browsers and ......
Read more >What does it take to support Node.js ESM? – The Guild
I have worked on all The Guild's libraries and graphql-js to support ESM. Here is how you can do it too.
Read more >Use the Node.js agent with ESM - Contrast Documentation
The Contrast Node.js agent provides limited support for using ECMAScript modules (ESM) in Node.js server-side applications.
Read more >How the module system, CommonJS & require works
js is an asynchronous event-driven JavaScript runtime and is the most effective when building scalable network applications. Node.js is free of ...
Read more >How to Create a Hybrid NPM Module for ESM and CommonJS.
Author your code in ES6, ES-Next or Typescript using import and export. From this base, you can import either ES modules or CommonJS...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
module
, and instead uses the newexports
specification, and in particular conditional exports, so simply adding the following should work:Note that this will enforce encapsulation, so anybody doing something like
import "@aws-sdk/client-s3/lib/some-file.js"
will be broken… but you probably want that.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.