Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Jun 7, 2024

Troubleshoot "Cannot find module $amplify/env/<function-name>"

When deploying a Amplify Gen 2 app, you may encounter the error message Cannot find module $amplify/env/<function-name> in your frontend build on Amplify Console. This error occurs when your framework tsconfig.json configuration picks up the amplify directory and tries to resolve it as a module. This module is a placeholder for environment variables that are injected at build time by Amplify. To resolve this error, you need to exclude the amplify directory.

To exclude the amplify directory in your tsconfig.json, add the following lines to the exclude section:

"exclude": ["amplify/**/*"]

Amplify will perform type-checking on sandbox and pipeline-deploy using the tsconfig local to the Amplify backend amplify/tsconfig.json. If you'd like to extend your base configuration you can add it to the localized tsconfig.

Alternatively, if you work within a monorepo you can move your backend to its own package and export the Schema and outputs for ease of sharing with your other apps. For example, in your backend package's package.json

"name": "my-backend",
"private": true,
"exports": {
"./schema": "./amplify/data/resource.ts",
"./outputs": "./amplify_outputs.json"