Skip to content
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

fix: provide ES module wrapper using conditional exports #2783

Closed
wants to merge 2 commits into from

Conversation

trivikr
Copy link
Member

@trivikr trivikr commented Sep 14, 2021

Issue

Attempt to fix: #2754

Description

Add ESModule wrapper using conditional exports, so that import in Node.js will use ES module.

Testing

Linked packages from workspace using the following command:

$ pwd
/home/trivikr/workspace/aws-sdk-js-v3/clients/client-s3

$ npm link                      
...
/local/home/trivikr/.fnm/node-versions/v14.17.4/installation/lib/node_modules/@aws-sdk/client-s3 -> /local/home/trivikr/workspace/aws-sdk-js-v3/clients/client-s3

The error is still thrown when test.mjs is run after running npm link @aws-sdk/client-s3

$ cat test.mjs
import { S3 } from "@aws-sdk/client-s3";

Additional context

API reference: https://nodejs.org/api/packages.html#packages_approach_1_use_an_es_module_wrapper


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@trivikr trivikr closed this Sep 14, 2021
@trivikr trivikr reopened this Sep 14, 2021
@trivikr
Copy link
Member Author

trivikr commented Sep 14, 2021

Adding "type": "module" doesn't help, as we have to export with .js files.

The test code fails with:

internal/process/esm_loader.js:74
    internalBinding('errors').triggerUncaughtException(
                              ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/local/home/trivikr/workspace/aws-sdk-js-v3/clients/client-s3/dist/es/S3Client' imported from /local/home/trivikr/workspace/aws-sdk-js-v3/clients/client-s3/dist/es/index.js
    at finalizeResolution (internal/modules/esm/resolve.js:285:11)
    at moduleResolve (internal/modules/esm/resolve.js:708:10)
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:819:11)
    at Loader.resolve (internal/modules/esm/loader.js:89:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:242:28)
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:73:40)
    at link (internal/modules/esm/module_job.js:72:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

@trivikr trivikr closed this Sep 14, 2021
@trivikr trivikr deleted the es-module-wrapper branch September 14, 2021 00:55
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CommonJS dist is imported instead of ESModule when using Node.js with ESModules, causing import errors.
1 participant