-
Notifications
You must be signed in to change notification settings - Fork 579
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
CommonJS dist is imported instead of ESModule when using Node.js with ESModules, causing import errors. #2754
Comments
Have the same issue |
Seems to have been caused by the update to Typescript 4.4 in 3.29 (works fine in 3.28 which was built with TS 4.3) Excerpt from
From
Wild guess is that it's an incompatibility between UPDATE: Logged a bug with TS team @ microsoft/TypeScript#45813 |
Downgrade PRs to merge if a better solution is not available before |
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. |
Describe the bug
When importing the SDK from a plain ESModule file in Node.js (i.e. without using a bundler), Node.js attempts to import the CommonJS dist (
@aws-sdk/*/dist/cjs
) instead of the ESModule dist. This causes an error due to missing named exports, as Node.js can't translate the CommonJS exports to named exports and only exposes adefault
export.Your environment
SDK version number
@aws-sdk/client-dynamodb@3.29.0
Is the issue in the browser/Node.js/ReactNative?
Node.js
Details of the browser/Node.js/ReactNative version
Tested on Node.js
v16.8.0
,v14.17.6
,v12.22.1
.Steps to reproduce
package.json
:main.js
:Then run
node main.js
.Observed behavior
This error occurs:
Expected behavior
The package should be imported and work using named imports, without having to use a default import.
Additional context
The error message does give a workaround, but this workaround is unergonomic and requires even more changes when migrating to ESModules. With many packages moving to being pure ESM (whether we like it or not), this problem is just adding unnecessary work when users a forced to move to ESM.
The SDK should define the
exports
field in thepackage.json
instead of justmain
andmodule
(which Node.js ignores). See Dual CommonJS/ES module packages. Additionally, the ESModule dist needs to add file extensions to its imports, i.e.import ... "./foo.js";
orimport ... "./foo/index.js";
instead ofimport ... "./foo";
(doing this would probably also help with #1289).The text was updated successfully, but these errors were encountered: