question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A Node.js application written in ESM uses CommonJS distribution of the SDK

See original GitHub issue

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:

// 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

https://user-images.githubusercontent.com/16024985/137387077-75425c67-ccc1-43e9-a025-7786b248116d.mov

Describe the solution you’d like

The Node.js application written in ESM should use distribution in dist-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 https://github.com/aws/aws-sdk-js-v3/issues/2889 to avoid increasing install size.

Additional context

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
simonbuchancommented, Oct 14, 2021

This one should actually be pretty easy to fix, assuming es doesn’t assume browser: the current package.json files have:

  "main": "./dist-cjs/index.js",
  "module": "./dist-es/index.js",

which was the bundler convention, but the native Node ESM support ignores module, and instead uses the new exports specification, and in particular conditional exports, so simply adding the following should work:

  "exports": {
    "require": "./dist-cjs/index.js",
    "import": "./dist-es/index.js",
  },

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.

0reactions
github-actions[bot]commented, Oct 28, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found