Skip to content

Commit 232b70a

Browse files
ykethanjosefaidt
andauthored
adds Cannot find module $amplify/env/<function-name> troubleshooting doc (#7681)
* adds cannot find module troubleshooting doc * update name * nit update function * nit update function * Update src/pages/[platform]/build-a-backend/troubleshooting/cannot-find-module-amplify-env/index.mdx --------- Co-authored-by: josef <josef.aidt@gmail.com>
1 parent 4fb66c5 commit 232b70a

File tree

2 files changed

+54
-0
lines changed
  • src
    • directory
    • pages/[platform]/build-a-backend/troubleshooting/cannot-find-module-amplify-env

2 files changed

+54
-0
lines changed

src/directory/directory.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,9 @@ export const directory = {
672672
},
673673
{
674674
path: 'src/pages/[platform]/build-a-backend/troubleshooting/stack-cdktoolkit-already-exists/index.mdx'
675+
},
676+
{
677+
path: 'src/pages/[platform]/build-a-backend/troubleshooting/cannot-find-module-amplify-env/index.mdx'
675678
}
676679
]
677680
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { getCustomStaticPath } from '@/utils/getCustomStaticPath';
2+
3+
export const meta = {
4+
title: 'Troubleshoot "Cannot find module $amplify/env/<function-name>"',
5+
description: 'Addressing "Cannot find module $amplify/env/<function-name>" error message',
6+
platforms: [
7+
'angular',
8+
'javascript',
9+
'nextjs',
10+
'react',
11+
'react-native',
12+
'vue'
13+
]
14+
};
15+
16+
export function getStaticPaths() {
17+
return getCustomStaticPath(meta.platforms);
18+
}
19+
20+
export function getStaticProps(context) {
21+
return {
22+
props: {
23+
meta
24+
}
25+
};
26+
}
27+
28+
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.
29+
30+
To exclude the `amplify` directory in your `tsconfig.json`, add the following lines to the `exclude` section:
31+
32+
```ts title='tsconfig.json'
33+
{
34+
"exclude": ["amplify/**/*"]
35+
}
36+
```
37+
38+
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.
39+
40+
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`
41+
42+
```json title='package.json'
43+
{
44+
"name": "my-backend",
45+
"private": true,
46+
"exports": {
47+
"./schema": "./amplify/data/resource.ts",
48+
"./outputs": "./amplify_outputs.json"
49+
}
50+
}
51+
```

0 commit comments

Comments
 (0)