Lambda: Can't use typescript module files #21635
Labels
@aws-cdk/aws-lambda-nodejs
bug
This issue is a bug.
effort/small
Small work item – less than a day of effort
p2
Describe the bug
We've tried to compile ESM output (.mjs) files from .mts (TypeScript Module) files via CDK "NodejsFunction". We don't want to change everything in our project to be JavaScript module code. So the only option is to use .mjs, or in our case, .mts files.
But someone thought it is a good idea to prohibit any other file extensions than .jsx?, .tsx? or .mts. So we're constantly getting an error that .mts is not valid. (which it is and should be allowed)
aws-cdk/packages/aws-cdk-lib/aws-lambda-nodejs/lib/function.ts
Line 165 in 28914bd
As soon as I remove the referenced line from the functions.js it compiles and deploys fine ...
Expected Behavior
At least .mts should be allowed as well if there is .ts and .mjs allowed.
https://www.typescriptlang.org/docs/handbook/esm-node.html#new-file-extensions
Maybe it is a good idea to allow .cjs and .cts as well these days 😅
Current Behavior
Error "Only JavaScript or TypeScript entry files are supported." is thrown even for perfectly valid TypeScript files. Probably even for perfectly valid JavaScript files with the ending .cjs.
Reproduction Steps
Stack code to create lambda using mts file and ESM format.
Contents of specified DummyLambda.mts can be any typescript code. Doenst matter for generating the error. The file isn't even required to exist.
Possible Solution
Regarding to https://www.typescriptlang.org/docs/handbook/esm-node.html#new-file-extensions at least .mts should be allowed. I would suggest to allow .cjs and .cts as well.
Additional Information/Context
No response
CDK CLI Version
2.37.1
Framework Version
No response
Node.js Version
All
OS
All
Language
Typescript
Language Version
All
Other information
No response
The text was updated successfully, but these errors were encountered: