Bug: `sam build` continues even if Typsecript compilation fails
See original GitHub issueDescription:
After adding an intentional TS error (e.g. renamed a variable without refactoring), and running sam build
, I’m told “Build Succeeded”. Running tsc
directly shows the error correctly.
My directory structure is as follows:
<root>
|--> app
| |--> node_modules
| |--> src
| | |--> app.ts # and other TS files
| |--> package.json # and other config files
| |--> tsconfig.json
|--> node_modules # for building e.g. rimraf
|--> package.json # ^^
|--> samconfig.toml
|--> template.yaml
I run sam build
from the root dir. In template.yml
I have this (partial example):
Function:
Type: AWS::Serverless::Function
# ...
Metadata:
BuildMethod: esbuild
BuildProperties:
Minify: false
Target: es2020
Sourcemap: true
EntryPoints:
- src/app.ts
To work around this, I have a wrapper shell script in which I call the build
function to run tsc
before sam build
(partial example):
#!/bin/bash
set -e
function build() {
clean
(cd app; npx tsc) # `sam build` seems to continue even if TSC fails ... ?
sam build "$@"
validate
}
"$@"
So I start the build via ./scripts.sh build
.
Steps to reproduce:
Create a simple Typescript / SAM project. Add a line of code which causes tsc
to fail. Run sam build
and observe that it does not indicate failure.
Observed result:
sam build
does not report tsc
errors / does not abort the build process on such errors.
Expected result:
sam build
should abort the process if tsc
fails.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: Manjaro Linux
sam --version
: 1.55.0- AWS region: N/A
Issue Analytics
- State:
- Created a year ago
- Comments:6 (4 by maintainers)
@JoshMcCullough As far as I can tell from the code, we are: https://github.com/aws/aws-lambda-builders/blob/develop/aws_lambda_builders/workflows/nodejs_npm_esbuild/esbuild.py#L98
Thanks for raising this issue to us. To sum up, aws-lambda-builders (the library that
sam build
) uses esbuild to transpile Typescript back to Javascript instead of usingtsc
. Some things that will causetsc
to fail might not fail for esbuild, hence your observed result. Feel free to (re)open an issue for anything you might find!