smithy-lang/smithy-typescript

ESM exports broken in module environment

Opened this issue · 2 comments

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.

I get same issue here too using Vite as bundler but I was able to workaround it using this in Vite config:

const config = defineConfig({
  optimizeDeps: {
    exclude: ['@smithy/shared-ini-file-loader'],
  },
 // other config
}
```