-
Notifications
You must be signed in to change notification settings - Fork 46
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
Amplify deploy fails when using function resolver with env by TypeScript error #1374
Comments
Hey @mm-k-takashima, thank you for reaching out. I was able to reproduce the issue. Marking as bug for further investigation. |
@mm-k-takashima on the local sandbox could you remove the |
I tried it.
// remove @ts-noncheck directive
import { env } from '$amplify/env/function-with-env';
And I confirmed .amplify/generated/env/function-with-env.ts generation has been succeeded. // This file is auto-generated by Amplify. Edits will be overwritten.
export const env = process.env as LambdaProvidedEnvVars & AmplifyBackendEnvVars;
/** Lambda runtime environment variables, see https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime */
type LambdaProvidedEnvVars = {
/** The handler location configured on the function. */
_HANDLER: string;
/** The X-Ray tracing header. This environment variable changes with each invocation. */
_X_AMZN_TRACE_ID: string;
/** The default AWS Region where the Lambda function is executed. */
AWS_DEFAULT_REGION: string;
/** The AWS Region where the Lambda function is executed. If defined, this value overrides the AWS_DEFAULT_REGION. */
AWS_REGION: string;
/** The runtime identifier, prefixed by AWS_Lambda_ (for example, AWS_Lambda_java8). */
AWS_EXECUTION_ENV: string;
/** The name of the function. */
AWS_LAMBDA_FUNCTION_NAME: string;
/** The amount of memory available to the function in MB. */
AWS_LAMBDA_FUNCTION_MEMORY_SIZE: string;
/** The version of the function being executed. */
AWS_LAMBDA_FUNCTION_VERSION: string;
/** The initialization type of the function, which is on-demand, provisioned-concurrency, or snap-start. */
AWS_LAMBDA_INITIALIZATION_TYPE: string;
/** The name of the Amazon CloudWatch Logs group for the function. */
AWS_LAMBDA_LOG_GROUP_NAME: string;
/** The name of the Amazon CloudWatch Logs stream for the function. */
AWS_LAMBDA_LOG_STREAM_NAME: string;
/** AWS access key. */
AWS_ACCESS_KEY: string;
/** AWS access key ID. */
AWS_ACCESS_KEY_ID: string;
/** AWS secret access key. */
AWS_SECRET_ACCESS_KEY: string;
/** AWS Session token. */
AWS_SESSION_TOKEN: string;
/** The host and port of the runtime API. */
AWS_LAMBDA_RUNTIME_API: string;
/** The path to your Lambda function code. */
LAMBDA_TASK_ROOT: string;
/** The path to runtime libraries. */
LAMBDA_RUNTIME_DIR: string;
/** The locale of the runtime. */
LANG: string;
/** The execution path. */
PATH: string;
/** The system library path. */
LD_LIBRARY_PATH: string;
/** The Node.js library path. */
NODE_PATH: string;
/** For X-Ray tracing, Lambda sets this to LOG_ERROR to avoid throwing runtime errors from the X-Ray SDK. */
AWS_XRAY_CONTEXT_MISSING: string;
/** For X-Ray tracing, the IP address and port of the X-Ray daemon. */
AWS_XRAY_DAEMON_ADDRESS: string;
/** The environment's time zone. */
TZ: string;
};
/** Amplify backend environment variables available at runtime, this includes environment variables defined in `defineFunction` and by cross resource mechanisms */
type AmplifyBackendEnvVars = {
API_HOST: string;
API_KEY: string;
}; |
Hey @mm-k-takashima, apologies for the delay. Wasn't able to reproduce the issue. |
@ykethan Thank you for your reasearch. version: 1
backend:
phases:
build:
commands:
- echo "API_HOST=$API_HOST" >> amplify/.env # Tried to create an adapter class for backend environment variable.
- npm ci
- npx amplify pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
artifacts:
baseDirectory: .next
files:
- '**/*'
cache:
paths:
- .next/cache/**/*
- node_modules/**/* As an additional context, I am using Next.js. This may be affecting this.
{
"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,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./app/*"],
"@@/*": ["./*"],
"$amplify/*": ["./.amplify/generated/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true
};
export default nextConfig;
{
"name": "amplify-testing-geo",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"test": "vitest --passWithNoTests",
"lint": "next lint",
"format": "prettier --write --ignore-path .gitignore './**/*.{js,jsx,ts,tsx,json,css}' && next lint --fix"
},
"volta": {
"node": "20.12.0",
"npm": "10.5.0"
},
"dependencies": {
"@aws-amplify/geo": "^3.0.27",
"@aws-amplify/ui-react": "^6.1.8",
"@aws-amplify/ui-react-geo": "^2.0.13",
"aws-amplify": "^6.0.28",
"dotenv": "^16.4.5",
"next": "14.1.4",
"prism-react-renderer": "^2.3.1",
"react": "^18.2.0",
"react-code-block": "^1.0.0",
"react-dom": "^18.2.0",
"react-icons": "^5.1.0"
},
"devDependencies": {
"@aws-amplify/backend": "^0.13.0",
"@aws-amplify/backend-cli": "^0.13.0",
"@testing-library/react": "^14.3.1",
"@types/node": "^20.12.7",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.25",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@vitejs/plugin-react": "^4.2.1",
"aws-cdk-lib": "^2.138.0",
"constructs": "^10.3.0",
"esbuild": "^0.20.2",
"eslint": "^8.57.0",
"eslint-config-next": "14.1.4",
"eslint-config-prettier": "^9.1.0",
"jsdom": "^24.0.0",
"lefthook": "^1.6.10",
"prettier": "^3.2.5",
"tsx": "^4.7.2",
"typescript": "^5.4.5",
"vitest": "^1.5.0"
}
}
Sorry, this cannot be done immediately. Could you please wait a week or so? |
Hey sure, do add a reply on this thread. would be happy in diving into this. |
I have Similar errors.
tsconfig settings and env file generation have completed successfully. |
In addition to tsconfig.json in the amplify directory, the problem was resolved by setting the following settings as the paths of tsconfig.json directly under the next.js project.
But doing so will result in a new type error.
This can be resolved by manually setting unknown, but it takes time. |
@ykethan As it turns out, the first problem shown However, instead of the first problem being resolved, I now have a problem regarding ProcessEnv as indicated by @rnrnstar2 in the file:
Should we create another assignment on this issue or should we continue in this thread? |
Hey @rnrnstar2 @mm-k-takashima, did run a similar error recently on the frontend build with nextjs
adding a exclude with |
@ykethan |
@mm-k-takashima thank you for the confirmation. Marking this as documentation, to add this information to the troubleshooting document. |
I'm running into the same issue with a Vue + Vite project, and neither adding the (for clarification's sake, here's my {
"extends": "@vue/tsconfig/tsconfig.dom.json",
"include": ["env.d.ts", "src/**/*", "src/**/*.vue", "amplify/**/*", ".amplify/generated/**/*"],
"exclude": ["src/**/__tests__/*"],
"compilerOptions": {
"composite": true,
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"$amplify/*": [
"../.amplify/generated/*"
]
}
}
} Happy to give whatever other info can be helpful |
Hey folks 👋 there are a few default tsconfig configurations that appear to be picking up the generated files from Amplify. We'll work towards documenting this soon, and maybe a message/codemod to help avoid this, but in the meantime you should be able to exclude the {
"exclude": ["amplify/**/*", ".amplify/**/*"]
} Amplify will perform type-checking on sandbox and pipeline-deploy using the tsconfig local to the amplify backend ( 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 {
"name": "my-backend",
"private": true,
"exports": {
"./schema": "./amplify/data/resource.ts",
"./outputs": "./amplify_outputs.json"
}
} |
Just letting you all know, I had this exact problem, excluding the files solved it immediately. I suppose it's already on the works but changing the cli tool for the init to modify the tsconfig.json file to add those lines might be a very good Idea. I'm thankful I found this. Good luck everyone. |
I seem to still be having the issue even when excluding it. It works with my sandbox but as soon as I push it to github and the build starts, I get this: This is going to sound crazy and I don't know why it is but this only happened when I renamed a folder to an uppercase letter instead of a lowercase letter. I reverted my commit back and forth to see. That is literally the only difference. Is there maybe something that gets cached when this runs?
|
Hey @CBougoZ is your function named |
Hi @josefaidt, Please, tell me that I am missing something obvious... |
@CBougoZ the generated env file name is based on the Function name, which if not specified falls back to the directory name. Can you specify |
@josefaidt |
No worries @CBougoZ! Glad to hear you're back up and running! Closing the issue with the documentation merge aws-amplify/docs#7681 |
Environment information
Description
Code
Structure
Implementations
Others
Error detail
Sandbox deploy is succeeded. But deploy on Amplify CI/CD is failed.
Deploy log
Expected
I want to meet these usecases.
What method should I take?(How to avoid TS check, wait for fix, or else ...)
The text was updated successfully, but these errors were encountered: