amplify-cli: Can't get TypeScript for Lambdas working in new environment
Before opening, please confirm:
- I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
- I have searched for duplicate or closed issues.
- I have read the guide for submitting bug reports.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
How did you install the Amplify CLI?
yarn
If applicable, what version of Node.js are you using?
No response
Amplify CLI Version
7.5.2
What operating system are you using?
Windows
Amplify Categories
function
Amplify Commands
configure project, env, push
Describe the bug
Trying to spin up a new environment from an existing setup (we already have dev and live, I’m creating a staging) and now getting some new errors with our Lambdas and I’m not sure why as these haven’t appeared on the other two environments.
We are using TypeScript for our Lambdas and build that into JS by having a command in our package.json for each Lambda.
I’ve gone through what its complaining about and tried installing TypeScript globally in the pre-build step, then install the missing types its complaining about but still it can’t find what its wanting and now I’m at a loss. Any pointers what I’ve doing wrong?
I’d follow the instructions on how to do this but as I’ve already got an issue open explaining they are incorrect (https://github.com/aws-amplify/amplify-cli/issues/8668) I feel I’m kind of on my own here 😐
Expected behavior
I can’t see why this would have worked on the dev/live environments if it is failing on this new one. Confused as to why its an issue now?
With Typescript install globally via the build settings and a local tsconfig file to the Lambda I can’t see why it wouldn’t work?
Reproduction steps
Tricky as ever as this is all part of a huge project, you might be able to trim these steps down some.
Have an existing environment with a Lambda called “peteTest” in it with the files included below.
Add a line to your scripts section of you project root package.json:
“amplify:peteTest”: “cd amplify/backend/function/peteTest && tsc -p ./tsconfig.json”
In your build settings add this pre-build script so that TypeScript is install globally:
backend: phases: build: commands: - npm i -g typescript
Create a new branch. Connect your branch in the CI. Trigger the CI to build your branch. It should fail claiming to not find types.
GraphQL schema(s)
# Put schemas below this line
Log output
# Put your logs below this line
Additional information
package.json in the /src folder of your Lambda (/amplify/backend/functions/peteTest/src):
{
"name": "peteTest",
"version": "2.0.0",
"description": "Lambda function generated by Amplify",
"main": "index.js",
"license": "Apache-2.0",
"dependencies": {
"axios": "^0.21.1",
"graphql": "^15.5.0",
"graphql-tag": "^2.11.0"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.72",
"@types/aws-sdk": "^2.7.0",
"@types/node": "^16.11.10",
"typescript": "^4.1.5"
}
}
tsconfig.json in the /src folder of our Lambda (/amplify/backend/functions/peteTest/src )
{
"compilerOptions": {
"strict": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"lib": ["dom", "esnext"],
"module": "commonjs",
"moduleResolution": "node",
"skipLibCheck": true,
"resolveJsonModule": true,
"outDir": "./src",
"baseUrl": "./",
"rootDir": "./src",
"paths": {
"src": ["./src"]
},
"noFallthroughCasesInSwitch": true,
"noImplicitAny": false,
"declaration": false,
"removeComments": true,
"noImplicitReturns": true,
"noUnusedLocals": false,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true
},
"include": ["./src"],
"exclude": ["src/node_modules", "src/**/*.spec.ts"]
}
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (8 by maintainers)
@sachscode that seems to have unstuck whatever it is!
So to sum up if it happens again (hello future me!):
Now I have green lights 😃