-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Closed
Labels
@aws-cdk/aws-lambda-nodejsbugThis issue is a bug.This issue is a bug.effort/smallSmall work item – less than a day of effortSmall work item – less than a day of effortp2
Description
Although Lambda now supports Node v14:
.mjsentry files are rejected by a regex pattern in aws-lambda-nodejsesbuildis transpiling the scripts tocjsformat (commonjs) but BundlingOptions provides no means to specifyformat: "esm", and consequently esbuild polyfillsimport.metawhich breaks all of its uses in the scripts
Reproduction Steps
lib/my-stack.mjs:
export class MyStack extends Stack {
constructor(scope, id, props) {
super(scope, id, props);
// ...
new NodejsFunction(this, 'Example', {
runtime: Runtime.NODEJS_14_X,
entry: 'src/entry-file.mjs',
bundling: {
target: 'es2020',
// format: 'esm', <-- should be able to pass this option here
},
};
// ...
}
}
src/entry-file.mjs:
export async function Example() {
return import.meta.url;
}
What did you expect to happen?
entry-file.mjsto be allowed to be used as an entry file.import.metato be defined andExample()to return a string.
What actually happened?
Error: Only JavaScript or TypeScript entry files are supported.Example()returns undefined sinceimport.metais polyfilled with an empty plain object.
Environment
- CDK CLI Version : n/a
- Framework Version:
- Node.js Version: 14.13.0
- OS : n/a
- Language (Version):
Other
-
For the
.mjsextension:
if (!/\.(jsx?|tsx?)$/.test(entry)) { -
Allow passing in the
formatoption toesbuild:
aws-cdk/packages/@aws-cdk/aws-lambda-nodejs/lib/bundling.ts
Lines 141 to 158 in 5d71d8e
const esbuildCommand: string = [ npx, 'esbuild', '--bundle', pathJoin(inputDir, this.relativeEntryPath), `--target=${this.props.target ?? toTarget(this.props.runtime)}`, '--platform=node', `--outfile=${pathJoin(outputDir, 'index.js')}`, ...this.props.minify ? ['--minify'] : [], ...this.props.sourceMap ? ['--sourcemap'] : [], ...this.externals.map(external => `--external:${external}`), ...loaders.map(([ext, name]) => `--loader:${ext}=${name}`), ...defines.map(([key, value]) => `--define:${key}=${value}`), ...this.props.logLevel ? [`--log-level=${this.props.logLevel}`] : [], ...this.props.keepNames ? ['--keep-names'] : [], ...this.relativeTsconfigPath ? [`--tsconfig=${pathJoin(inputDir, this.relativeTsconfigPath)}`] : [], ...this.props.metafile ? [`--metafile=${pathJoin(outputDir, 'index.meta.json')}`] : [], ...this.props.banner ? [`--banner='${this.props.banner}'`] : [], ...this.props.footer ? [`--footer='${this.props.footer}'`] : [], ].join(' ');
This is 🐛 Bug Report
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
@aws-cdk/aws-lambda-nodejsbugThis issue is a bug.This issue is a bug.effort/smallSmall work item – less than a day of effortSmall work item – less than a day of effortp2