Bug: Middy requires special flag in `tsconfig.json` to be imported as esm
See original GitHub issueBug description
when using middy i get the following error TypeError: core_1.default is not a function
Possible Solution
updating the tsconfig.json with "esModuleInterop": true
solved the problem as suggested in middy’s github Issue https://github.com/middyjs/middy/issues/203
Environment
- Powertools version used: 0.2.0
- Packaging format (Layers, npm): npm
- AWS Lambda function runtime: node v14
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
TSConfig Reference - Docs on every TSConfig option
A module file is a file that has imports and/or exports. Without this flag, using an export from a UMD module requires an...
Read more >Troubleshooting Handbook: tsconfig.json
Selected flags and why we like them: esModuleInterop : disables namespace imports ( import * as foo from "foo" ) and enables CJS/AMD/UMD...
Read more >node.js - converting all typescript to javascript in the backend
I have written an app with typescript for the Node JS backend. Ar the moment in the package.json I am using the below...
Read more >TypeScript - Parcel
While Parcel's default transpiler for TypeScript is much faster than TSC, you may need to use TSC if you are using some configuration...
Read more >CommonJS vs native ECMAScript modules | ts-node
You can choose to either transform to CommonJS or to preserve the native import syntax, using node's native ESM support. Configuration is different...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Using ESM by default in Middy was the plan. However …
(a) Recent discoveries that Lambda with ESM cannot access node_modules pre-bundled in the runtime or shared in a lambda layer has made us stop and rethink. This isn’t documented anywhere that I know of 😦. I’ve reported this regression to AWS Support and was told to use v3 of the SDK instead.
(b) We would consider migrating to using v3 of the SDK (I even tried a year ago), however, RDS.Signer is not implemented yet (https://github.com/aws/aws-sdk-js-v3/issues/1823 @AllanZhengYP). Using v3 of the SDK would increase lambda bundle size compared to v2 of the SDK. I would suggest AWS pre-bundle all v3 packages in the runtime (https://github.com/aws/aws-sdk-js-v3/issues/2149), but this wouldn’t help with ESM support because lambda handlers wouldn’t be able to access them anyways (a) 🤷
© Even if (a), or (b*2) are resolved, the X-Ray SDK using dynamic require breaks when using ESM (https://github.com/aws/aws-xray-sdk-node/issues/482 @NathanielRN).
Based on the current state of ESM support from AWS outlined above, the new plan for middy@3 will be to continue providing CommonJS for another year sadly. We’re going to wait (2-3 week) and see if ((a OR b*2) AND c) are resolved before making a final decision and mint a beta release.
Cross posted from: https://github.com/middyjs/middy/issues/584
cc @lmammino
Put this
on-hold
as this will be solved when we upgrade to middy v3.@saragerion I wonder if we should make this note in our doc? (for all utils, in middy tab). On the other hand, this is middy specific and middy v3 will be released when NodeJS16 is supported in Lambda. We can wait to just upgrade once.
I’m inclined to wait and upgrade as we aren’t out of beta yet. What’s your thought?