使用任意tsconfig.json在VS代码调试中的打字稿AWS lambda的调用
我正在尝试通过SAM在VS Code Debugger下通过SAM编写的Lambda函数来运行代码,该功能已安装了AWS工具包。该代码确实成功地构建和部署到云中,但是在调试器下运行它的错误失败,并且在这个问题。
我的构建指定 eSmoduleInterop:true
in tsconfig.json
,而SAM构建忽略它,构建就像 Esmoduleop:false
。它似乎使用了以下任意 tsconfig.json
,而不是项目目录中的一个。如何使用我的 tsconfig.json
,或者至少将特定的编译器选项传递给 tsc ?
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"typeRoots": [
"node_modules/@types"
],
"types": [
"node"
],
"rootDir": ".",
"inlineSourceMap": true
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以分享您的启动配置吗?如果您使用
InvoketArget.target.template
启动config(它可以在lambda项目中期望samtemplate.yaml
文件),它是否有效?当您使用
InvoketArget.target.target.target.target.target.code:Code
(a code (a)时,当前是aws工具包的限制。 功能请求将不胜感激!):Can you share your launch config? Does it work if you use a
invokeTarget.target:template
launch config (which expects a SAMtemplate.yaml
file in your lambda project)?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
我使用vscodes中的一些脚本魔术
启动
&tasks.json
并稍微修改tsconfig.json
,并在SAM模板中启用Sourcemap选项。.vscode/laining.json
代码:helloworldfunction
。此配置:target:“代码”
),指定lambda处理程序(lambdahandler:“ app.lambdahandler”
)和项目root。x86_64
,并将运行时指定为nodejs20.x
,确保与最新的node.js功能和性能改进。观看所有
.gitignore
build> build/
和** aws-toolkit-tsconfig.json的条目通过Git跟踪构建工件和特定的配置文件。这可以使存储库保持清洁,并避免由环境特定文件引起的潜在冲突或差异。
tasks.json
in.vscode/
npm安装
的新任务,Typescript编译和帖子添加了补偿任务。这些任务确保安装了所有依赖项,将打字稿汇编为JavaScript,并在编译后执行任何必要的清理或其他设置。tsconfig.json
sourcemap
true true允许生成源地图,这对于在生产环境中在生产环境中调试打字条至关重要将JavaScript编译回原始打字稿源代码。OUTDIR
,与源文件分开组织编译的文件,这有助于干净的部署。template.yaml
启用源地图:启用了源地图设置,允许AWS SAM在构建过程中使用源地图。理想情况下,我希望这样做才能自动处理一切。
从运行和调试菜单中选择“代码:helloworldfunction”,并享受调试
I worked around this limitations using some scripting magic in vscodes
launch.json
&tasks.json
and slightly modifying thetsconfig.json
and enabling the sourcemap option in the SAM template..vscode/launch.json
code:HelloWorldFunction
was added. This configuration:target: "code"
), specifying the lambda handler (lambdaHandler: "app.lambdaHandler"
) and the project root.x86_64
and specifies the runtime asnodejs20.x
, ensuring compatibility with the latest Node.js features and performance improvements.Watch All
), likely set up to compile TypeScript to JavaScript and watch for changes, ensuring that the latest code is always deployed and debugged..gitignore
build/
and**aws-toolkit-tsconfig.json
, preventing build artifacts and specific configuration files from being tracked by Git. This keeps the repository clean and avoids potential conflicts or discrepancies caused by environment-specific files.tasks.json
in.vscode/
npm install
, TypeScript compilation, and a post-compilation task were added. These tasks ensure that all dependencies are installed, the TypeScript is compiled to JavaScript, and any necessary cleanup or additional setup is performed after compilation.tsconfig.json
sourceMap
to true allows generation of source maps, which are crucial for debugging TypeScript in production environments as they map the compiled JavaScript back to the original TypeScript source code.outDir
, organizing compiled files separately from source files, which helps in clean deployments.template.yaml
Enabled Source Maps: The source map setting was enabled, allowing AWS SAM to use source maps during the build process. Ideally, I expected just doing this to handle everything automatically.
Select the code:HelloWorldFunction from the Run and Debug Menu and enjoy debugging ????
