question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: `sam build` continues even if Typsecript compilation fails

See original GitHub issue

Description:

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)

  1. OS: Manjaro Linux
  2. sam --version: 1.55.0
  3. AWS region: N/A

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

0reactions
lucashuycommented, Sep 7, 2022

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 using tsc. Some things that will cause tsc to fail might not fail for esbuild, hence your observed result. Feel free to (re)open an issue for anything you might find!

Read more comments on GitHub >

github_iconTop Results From Across the Web

esbuild (and TypeScript) Beta Support Feedback #3700 - GitHub
I think having TypeScript options bundled into Sam CLI as templates is a bad idea while everything is still being ironed out. I...
Read more >
Building TypeScript projects with AWS SAM CLI
AWS SAM now provides the capability to create a sample TypeScript project using a template. Since this feature is still in preview, ...
Read more >
Typescript compilation through Serverless failing
I have a Typescript-based Lambda function that compiles fine with tsc but when I attempt to deploy through Serverless, the Typescript ...
Read more >
TypeScript and AWS SAM | Serverless Office Hours - YouTube
... Principal Specialist Solutions Architect, and Daniel Mil, Software Dev Engineer, join Eric Johnson to talk about building Typescrip...
Read more >
Write your Lambda functions using Typescript with AWS SAM
You can use the Node.js runtime to run TypeScript code in AWS Lambda. Because Node.js doesn't run TypeScript code natively, you must first ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found