aws-amplify / aws-amplify/amplify-cli
Docs are misleading for getting TypeScript up and running for Lambdas
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 825
- Avg merge
- 11d 23h
- Merged PRs (30d)
- 2
Description
### Before opening, please confirm:
- [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-cli/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-cli/blob/master/CONTRIBUTING.md#bug-reports).
- [X] 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?
_No response_
### If applicable, what version of Node.js are you using?
_No response_
### Amplify CLI Version
6.3.1
### What operating system are you using?
Windows
### Amplify Categories
function
### Amplify Commands
add
### Describe the bug
The docs on how to get TypeScript running here https://docs.amplify.aws/cli/function/build-options/ do not match the default layout that `amplify function add` generates. This leads to a lot of wasted time and confusion. Better to give the examples for a vanilla setup rather than losing people with a custom hack around setup.
### Expected behavior
1. The location of the ts.config file should be made more clear, it should be "in the root of your function's folder" which it states but then the script we are told to add to our package.json assumes this file is in the `/src` folder.
2. The right package.json script if the ts.config is in the root is:
```
"amplify:": "cd amplify/backend/function/ && tsc -p ./tsconfig.json",
```
and not
```
"amplify:": "cd amplify/backend/function//src && tsc -p ./tsconfig.json && cd -",
```
as listed in the docs.
3. I've no idea what the `&& cd -` does at the end of the listed script comment in the docs but it blows up on Windows so I removed it.
4. There is talk of a '/lib' folder which in the example given is now a requirement to get this to work. Out of the box there is no lib folder so why not assume that they user can add their code directly into the `/src` folder. As its a *.ts file it will be ignored anyway. Chances are you might only have a few of your own files in here, why complicate it for first time users?
5. The ts.config doesn't work for the location mentioned in the docs for the script file, the values in it for /lib and /src are wrong. I've had to fix it to this with trial and error (it might not be 100% "right" but at least its working) with ts.config in the function root is:
```
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"lib": ["dom", "esnext"],
"module": "commonjs",
"moduleResolution": "node",
"skipLibCheck": true,
"resolveJsonModule": true,
"outDir": "./src",
"baseUrl": "./",
"rootDir": "./src",
"paths": {
"src": ["./src"]
}
},
"include": ["./src"],
"exclude": ["src/node_modules", "src/**/*.spec.ts"]
}
5. Make it much clearer where the script command needed should go as there is a package.json in the root of the function as well as the one in the root of the app. Ideally just say, "not in your functions package.json as amplify won't call that one" or something. Stops us double guessing and any doubts.
```
### Reproduction steps
1. create a function via `amplify function add`
2. create a simple module in /src/test.ts which exports something
3. rename your index.js to index.ts
4. import your test.js module with `import test from 'test';` and call it in your handler so show we are doing funky TS stuff.
5. with this vanilla setup now try to follow the instructions in the docs site https://docs.amplify.aws/cli/function/build-options/ to get TS running
6. scream in anger.
7. come log an issue on here to try to save others from having to scream in anger at losing several hours.
### GraphQL schema(s)
```graphql
# Put schemas below this line
```
### Log output
```
# Put your logs below this line
```
### Additional information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.