- Newest
- Most votes
- Most comments
The issues you're encountering with TypeScript in AWS Amplify Gen 2 are related to how Amplify handles TypeScript configurations and module resolution.
Regarding the exclusion of the amplify directory in tsconfig.json: This is actually intentional and recommended. The amplify directory contains placeholder modules that are injected at build time by Amplify. When your framework's TypeScript configuration picks up the amplify directory, it tries to resolve it as a module, which can cause the "Cannot find module $amplify/env/<function-name>" error during frontend builds. Excluding the amplify directory in tsconfig.json prevents these resolution errors.
As for importing TypeScript files as JavaScript files: This is related to how Amplify handles TypeScript compilation. Amplify performs its own type-checking on the backend using a localized tsconfig.json within the amplify directory. The imports using .js extensions are a pattern used because at runtime, the TypeScript files are compiled to JavaScript, and the imports need to reference the compiled JavaScript files.
For your specific use case of deploying an app with API calls that might exceed 60 seconds, Amplify does support longer execution times (up to 15 minutes as you mentioned), but the configuration can be complex due to how the TypeScript setup works.
If you're working in a project where you need to share code between frontend and backend, you might consider moving your backend to its own package and exporting the Schema and outputs for easier sharing with your frontend application.
Sources
Troubleshoot "Cannot find module $amplify/env/<function-name>" - AWS Amplify Gen 2 Documentation
Troubleshoot "Cannot find module $amplify/env/<function-name>" - AWS Amplify Gen 2 Documentation
Separate frontend and backend teams - AWS Amplify Gen 2 Documentation
I still can't deploy my app, I am getting errors of the sort: 2025-06-25T07:11:30.464Z [INFO]: # Executing command: npx ampx pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID
105
2025-06-25T07:11:34.048Z [INFO]: 7:11:33 AM Synthesizing backend...
106
2025-06-25T07:11:34.053Z [INFO]:
107
2025-06-25T07:11:34.400Z [INFO]: 7:11:34 AM ✔ Backend synthesized in 0.46 seconds
108
2025-06-25T07:11:34.400Z [INFO]: 7:11:34 AM Running type checks...
109
2025-06-25T07:11:35.069Z [INFO]: 7:11:35 AM ✔ Type checks completed in 0.66 seconds
110
2025-06-25T07:11:35.069Z [INFO]:
111
2025-06-25T07:11:35.176Z [INFO]:
112
2025-06-25T07:11:35.177Z [INFO]: [BackendBuildError] Unable to deploy due to CDK Assembly Error
113
∟ Caused by: [AssemblyError] Assembly builder failed
114
∟ Caused by: [Error] Cannot find module '/codebuild/output/src3034228947/src/Dressed-by-AI/amplify/data/resource.js' imported from /codebuild/output/src3034228947/src/Dressed-by-AI/amplify/backend.ts
115
Resolution: Check the Caused by error and fix any issues in your backend code
116
2025-06-25T07:11:35.177Z [WARNING]: ampx pipeline-deploy
117
Command to deploy backends in a custom CI/CD pipeline. This command is not inten
118
ded to be used locally.
119
Options:
120
--debug Print debug logs to the console
121
[boolean] [default: false]
122
--branch Name of the git branch being deployed
123
[string] [required]
124
--app-id The app id of the target Amplify app[string] [required]
125
--outputs-out-dir A path to directory where amplify_outputs is written. I
126
f not provided defaults to current process working dire
127
ctory. [string]
128
--outputs-version Version of the configuration. Version 0 represents clas
129
sic amplify-cli config file amplify-configuration and 1
130
represents newer config file amplify_outputs
131
[string] [choices: "0", "1", "1.1", "1.2", "1.3", "1.4"] [default: "1.4"]
132
--outputs-format amplify_outputs file format
133
[string] [choices: "mjs", "json", "json-mobile", "ts", "dart"]
134
-h, --help Show help [boolean]
135
2025-06-25T07:11:35.251Z [ERROR]: !!! Build failed
136
2025-06-25T07:11:35.252Z [INFO]: Please read more about Amplify Hosting's support for SSR frameworks to find if your build failure is related to an unsupported feature: https://docs.aws.amazon.com/amplify/latest/userguide/amplify-ssr-framework-support.html. You may also find this troubleshooting guide useful: https://docs.aws.amazon.com/amplify/latest/userguide/troubleshooting-ssr-deployment.html
137
2025-06-25T07:11:35.252Z [ERROR]: !!! Error: Command failed with exit code 1
138
2025-06-25T07:11:35.252Z [INFO]: # Starting environment caching...
139
2025-06-25T07:11:35.252Z [INFO]: # Environment caching completed
140
141
Absolutely insane stuff, I could have started and finished entire projects in the time it took me to try and understand this, and it still doesn't work.
Relevant content
- asked 4 years ago
- asked 2 years ago
- asked 4 years ago
