-
Notifications
You must be signed in to change notification settings - Fork 1.1k
adds Cannot find module $amplify/env/<function-name>
troubleshooting doc
#7681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
renebrandel
merged 5 commits into
aws-amplify:main
from
ykethan:add-env-var-troubleshooting
Jun 7, 2024
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
06583d8
adds cannot find module troubleshooting doc
ykethan 1d7e7b1
update name
ykethan 3bcedc8
nit update function
ykethan 601dd51
nit update function
ykethan 1c4b083
Update src/pages/[platform]/build-a-backend/troubleshooting/cannot-fi…
josefaidt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...tform]/build-a-backend/troubleshooting/cannot-find-module-amplify-env/index.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { getCustomStaticPath } from '@/utils/getCustomStaticPath'; | ||
|
||
export const meta = { | ||
title: 'Troubleshoot "Cannot find module $amplify/env/<function-name>"', | ||
description: 'Addressing "Cannot find module $amplify/env/<function-name>" error message', | ||
platforms: [ | ||
'angular', | ||
'javascript', | ||
'nextjs', | ||
'react', | ||
'react-native', | ||
'vue' | ||
] | ||
}; | ||
|
||
export function getStaticPaths() { | ||
return getCustomStaticPath(meta.platforms); | ||
} | ||
|
||
export function getStaticProps(context) { | ||
return { | ||
props: { | ||
meta | ||
} | ||
}; | ||
} | ||
|
||
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: | ||
|
||
```ts title='tsconfig.json' | ||
|
||
{ | ||
"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` | ||
|
||
```json title='package.json' | ||
{ | ||
"name": "my-backend", | ||
"private": true, | ||
"exports": { | ||
"./schema": "./amplify/data/resource.ts", | ||
"./outputs": "./amplify_outputs.json" | ||
} | ||
} | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.