smithy-lang / smithy-typescript

Smithy code generators for TypeScript. (in development)
Apache License 2.0
227 stars 85 forks source link

ESM exports broken in module environment #1437

Open DanielOrtel opened 1 week ago

DanielOrtel commented 1 week ago

When running in an ESM environment, shared-ini-file-loader(that I know of, but it's possible other packages are outputting incorrect ESM code as well) provides a broken entryfile, resulting in an error with build processes which are strict about this thing in general:

✘ [ERROR] No matching export in "../../node_modules/@smithy/shared-ini-file-loader/dist-es/index.js" for import "getSSOTokenFromFile"

    ../../node_modules/@aws-sdk/credential-provider-sso/dist-es/resolveSSOCredentials.js:4:9:
      4 │ import { getSSOTokenFromFile } from "@smithy/shared-ini-file-loader";

The reason for this is that in ESM, file extensions are mandatory, but the build process doesn't append these for the dist-es build. This is what the current @smithy/shared-ini-file-loader/dist-es/index.js looks like:

export * from "./getHomeDir";
export * from "./getProfileName";
export * from "./getSSOTokenFilepath";
export * from "./getSSOTokenFromFile";
export * from "./loadSharedConfigFiles";
export * from "./loadSsoSessionData";
export * from "./parseKnownFiles";
export * from "./types";

Manually adding the .js file extensions in my own node_modules folder fixes this, so this is 100% the issue for the build error. Correct ESM output should be:

export * from "./getHomeDir.js";
export * from "./getProfileName.js";
export * from "./getSSOTokenFilepath.js";
export * from "./getSSOTokenFromFile.js";
export * from "./loadSharedConfigFiles.js";
export * from "./loadSsoSessionData.js";
export * from "./parseKnownFiles.js";
export * from "./types.js";

Edit: may be an issue with the bundler, since running with a simple node command works, but to err on the side of caution, the es export should still contain the proper extensions.

kuhe commented 1 week ago

Similar to https://github.com/aws/aws-sdk-js-v3/issues/3622.