Skip to content
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

Type error: Cannot find module '$amplify/env/say-hello' or its corresponding type declarations. #1545

Closed
2 tasks done
nxia416 opened this issue May 22, 2024 · 2 comments
Closed
2 tasks done
Labels
duplicate This issue or pull request already exists pending-response Issue is pending response from author pending-triage Incoming issues that need categorization

Comments

@nxia416
Copy link

nxia416 commented May 22, 2024

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

v20.12.2

Amplify CLI Version

amplify gen2, 12.11.1

What operating system are you using?

Mac

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No

Describe the bug

I am following the template tutorial of Gen2 for nextjs page router . When trying to add the environment variables for a new function, the CDK deployment failed when running "npm run build":

image

the error message is
Type error: Cannot find module '$amplify/env/say-hello' or its corresponding type declarations.

I do have my amplify/tsconfig.json file configured (which is generated by the npx amplify create command):

@/amplify/tsconfig.json

{
  "compilerOptions": {
    "target": "es2022",
    "module": "es2022",
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "paths": {
      "$amplify/*": [
        "../.amplify/generated/*"
      ]
    }
  }
}

@/tsconfig.json

{
  "compilerOptions": {
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "paths": {
      "@/*": ["./*"]
    }
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
  "exclude": ["node_modules"]
}

here is the file structure:

image

Expected behavior

expect the deploy to success.

Are there any special configuration for typescript? It looks like a compiling problem.

Reproduction steps

  1. use amplify next-pages template
  2. add a new function called say-hello
  3. add a environment called NAME:
import { defineFunction } from "@aws-amplify/backend";

export const sayHello = defineFunction({
  // optionally specify a name for the Function (defaults to directory name)
  name: "say-hello",
  // optionally specify a path to your handler (defaults to "./handler.ts")
  entry: "./handler.ts",
  environment: {
    NAME: "World",
  },
});

  1. git push to trigger the deployment

Project Identifier

No response

Log output

# Put your logs below this line


Additional information

No response

Before submitting, please confirm:

  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.
@nxia416 nxia416 added the pending-triage Incoming issues that need categorization label May 22, 2024
@ykethan
Copy link
Member

ykethan commented May 22, 2024

Hey,👋 thanks for raising this! I'm going to transfer this over to our backend repository.
The issue appears to be similar to #1374, refer to the comment #1374 (comment) providing information mitigating this issue.

@ykethan ykethan transferred this issue from aws-amplify/amplify-cli May 22, 2024
@ykethan ykethan added duplicate This issue or pull request already exists pending-response Issue is pending response from author and removed duplicate This issue or pull request already exists labels May 22, 2024
@ykethan
Copy link
Member

ykethan commented May 28, 2024

Closing the issue as this is currently being tracked on #1374

@ykethan ykethan closed this as not planned Won't fix, can't repro, duplicate, stale May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists pending-response Issue is pending response from author pending-triage Incoming issues that need categorization
Projects
None yet
Development

No branches or pull requests

2 participants