awslabs / cognito-at-edge

Serverless authentication solution to protect your website or Amplify application
Apache License 2.0
189 stars 56 forks source link

Add `esModuleInterop = true` in tsconfig.json to enable bundle with Vite #79

Open wand2016 opened 1 year ago

wand2016 commented 1 year ago

What would you like to be added:

in tsconfig.json:

{
  "compilerOptions": {
+   "esModuleInterop": true
  },
  ...
}

Why is this needed:

The cognito-at-edge package is designed to be deployed to Lambda@Edge. Lambda@Edge does not support Lambda layers, and the function size limit is up to 1 MB. Consequently, some form of bundlers is required to deploy cognito-at-edge. (Running npm i cognito-at-edge resulted in a node_modules directory size of >1MB)

Unlike the sample repo, I adopted terraform for IaC and Vite as a bundler. The build and deploy processes worked fine, but I encountered the following runtime error:

TypeError: (0 , $.default) is not a function
    at new D (/.../dist/node_modules/cognito-at-edge/dist/index.js:1:1995)
    at t (/.../dist/index.js:1:499)

Node.js v18.18.0

By forking this repository, setting esModuleInterop = true, and running npm run build, the error was resolved.