Skip to content

Support subpath exports for typescript #4461

Open
@brandonryan

Description

@brandonryan

Describe the feature

Right now if you try to import say, all the commands for a client, you get a typescript error.

import * as s3Commands from "@aws-sdk/client-s3/dist-es/commands/index.js"
Could not find a declaration file for module '@aws-sdk/client-sqs/dist-es/commands/index.js'. '[path-to-project]/node_modules/.pnpm/@aws-sdk+client-sqs@3.272.0/node_modules/@aws-sdk/client-sqs/dist-es/commands/index.js' implicitly has an 'any' type.
  If the '@aws-sdk/client-sqs' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module '@aws-sdk/client-sqs/dist-es/commands/index.js';`

The module should instead provide exports path patterns to allow you to import any of the files in the module.

Use Case

I need to import all the commands in the module into an object, so I can look them up and do string manipulation on the keys. I am writing a web service that acts as an aws-sdk proxy because the module wont work in our legacy system.

Proposed Solution

I propose that the modules export using the nodejs "exports" feature in package.json

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

Removed the main, types, and module fields.

This has some added benefit, removing the requirement to import the dist folder and instead letting node resolve the import path. For example, instead of
"@aws-sdk/client-sqs/dist-es/commands/index.js
you can just write
"@aws-sdk/client-sqs/commands/index.js.

Other Information

You might have to add .mjs to all the import paths for module import, depending on the "mode" field in package.json. I'm not sure if nodejs is smart enough at runtime to resolve the module type when resolving the import paths without this. Had issues with it before.

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

SDK version used

3.272.0

Environment details (OS name and version, etc.)

Mac

Metadata

Metadata

Assignees

Labels

feature-requestNew feature or enhancement. May require GitHub community feedback.lEffort estimation: largep2This is a standard priority issuequeuedThis issues is on the AWS team's backlog

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions