Home > Software design >  Invocation of Typescript AWS Lambda in VS Code debug builds using arbitrary tsconfig.json
Invocation of Typescript AWS Lambda in VS Code debug builds using arbitrary tsconfig.json

Time:06-23

I'm trying to run code for a Lambda function written in Typescript via SAM under the VS Code debugger, which has AWS Toolkit installed. The code does build and deploy successfully to the cloud, but running it under the debugger fails with error described in this question.

My build specifies esModuleInterop: true in tsconfig.json, and the SAM build ignores it, building instead as if esModuleInterop: false. It appears to use an arbitrary tsconfig.json given below, instead of the one in the project directory. How can I get it to use my tsconfig.json, or at least pass specific compiler options to tsc?

{
"compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "typeRoots": [
        "node_modules/@types"
    ],
    "types": [
        "node"
    ],
    "rootDir": ".",
    "inlineSourceMap": true
}

CodePudding user response:

Can you share your launch config? Does it work if you use a invokeTarget.target:template launch config (which expects a SAM template.yaml file in your lambda project)?

It appears to use an arbitrary tsconfig.json given below, instead of the one in the project directory

That's currently a limitation of AWS Toolkit for VSCode when you invoke a typescript lambda with invokeTarget.target:code (a feature request would be appreciated!):

https://github.com/aws/aws-toolkit-vscode/blob/acbd172d8e0de799e880ba83aff1f6a5562f11af/src/shared/sam/debugger/typescriptSamDebug.ts#L137-L138

  • Related