-
Notifications
You must be signed in to change notification settings - Fork 165
Description
Expected Behavior
Description:
After upgrading @aws-lambda-powertools/parser
from version 2.16.0
to 2.17.0
, TypeScript is no longer able to resolve imports from specific submodules like helpers
and schemas
. This results in TS2307 errors ("Cannot find module '...' or its corresponding type declarations.").
Example Failing Imports (Working in v2.16.0):
import { JSONStringified } from "@aws-lambda-powertools/parser/helpers";
// Error: Cannot find module '@aws-lambda-powertools/parser/helpers' or its corresponding type declarations.ts(2307)
import { APIGatewayProxyEventV2Schema } from "@aws-lambda-powertools/parser/schemas";
// Error: Cannot find module '@aws-lambda-powertools/parser/schemas' or its corresponding type declarations.ts(2307)
Analysis of Changes Between v2.16.0 and v2.17.0:
The primary relevant change between these versions appears to be the introduction and utilization of the exports
field in the package.json
file in v2.17.0.
-
v2.16.0 Behavior (Inferred):
- In version 2.16.0 (and earlier), importing from paths like
@aws-lambda-powertools/parser/helpers
likely relied on Node.js/TypeScript's standard module resolution finding the relevantindex.js
/index.d.ts
files within thenode_modules/@aws-lambda-powertools/parser/helpers/
directory structure. Thepackage.json
for v2.16.0 likely did not use the top-levelexports
map in the same way as v2.17.0.
- In version 2.16.0 (and earlier), importing from paths like
-
v2.17.0 Behavior (
exports
map):- Version 2.17.0's
package.json
now includes a comprehensiveexports
map. This map explicitly defines all the public entry points for the package. - For example, it defines:
.
(the main entry point)./middleware
./schemas
./helpers
./envelopes
- and others...
- Crucially, for each entry point, it specifies different files for CommonJS (
require
) and ES Modules (import
), along with their corresponding type definition (.d.ts
) files.
// Excerpt from v2.17.0 package.json "exports": { // ... other entries "./helpers": { "require": { "types": "./lib/cjs/helpers/index.d.ts", "default": "./lib/cjs/helpers/index.js" }, "import": { "types": "./lib/esm/helpers/index.d.ts", "default": "./lib/esm/helpers/index.js" } }, "./schemas": { "require": { "types": "./lib/cjs/schemas/index.d.ts", "default": "./lib/cjs/schemas/index.js" }, "import": { "types": "./lib/esm/schemas/index.d.ts", "default": "./lib/esm/schemas/index.js" } } // ... other entries }
- Version 2.17.0's
Why This Causes the Error (Likely Scenario):
The exports
map provides more control over package entry points but requires the consuming project's tooling (TypeScript, Node.js) to understand it correctly.
- TypeScript
moduleResolution
: TypeScript's ability to interpret theexports
map depends heavily on thecompilerOptions.moduleResolution
setting intsconfig.json
.- Older settings like
"moduleResolution": "node"
(or"classic"
) generally do not fully support or respect theexports
map. They will try to look for files directly at paths likenode_modules/@aws-lambda-powertools/parser/helpers/index.d.ts
, fail (because the structure might have changed or theexports
map takes precedence), and report the TS2307 error. - Newer settings like
"moduleResolution": "node16"
,"nodenext"
, or"bundler"
are designed to work with theexports
map. They will correctly look up@aws-lambda-powertools/parser/helpers
in theexports
map and resolve it to the appropriate file (lib/esm/helpers/index.d.ts
orlib/cjs/helpers/index.d.ts
based on other settings likemodule
).
- Older settings like
Troubleshooting Attempted:
- Tried alternative import paths (e.g.,
.../lib/helpers
,.../lib/esm/helpers
) without success. - Updated
tsconfig.json
to use"module": "node16"
and"moduleResolution": "node16"
, but the issue persists. - Other Powertools modules (e.g., logger, metrics, tracer) are imported and resolved correctly with the same
tsconfig.json
settings.
Current Behavior
see above.
Code snippet
see above.
Steps to Reproduce
see above.
Possible Solution
No response
Powertools for AWS Lambda (TypeScript) version
2.17.0
AWS Lambda function runtime
22.x
Packaging format used
npm
Execution logs
Metadata
Metadata
Assignees
Labels
Type
Projects
Status