gpt4 book ai didi

node.js - 在 VS Code 中调试 Netlify 函数

转载 作者:行者123 更新时间:2023-12-04 13:55:11 29 4
gpt4 key购买 nike

我正在尝试在通过 netlify dev 执行的 netlify 函数内设置断点使用以下设置:
设置
安装 Netlify-CLI

npm install netlify-cli -g
netlify.toml
[build]
functions = "functions/"
functions/hello.js
exports.handler = async(event, context) => {
let output = `Hello, ${event.queryStringParameters.name}`
return { statusCode: 200, body: output};
}
这是一个 sample project与设置

您应该可以通过 netlify dev 正常运行
netlify dev screenshot
这将在以下地址公开该函数:
http://localhost:8888/.netlify/functions/hello?name=Kyle
调试尝试 Launch.config在 VSCode 中,您应该能够使用 launch.config 设置调试。 .我试过以下配置
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\node_modules\\.bin\\netlify",
"args": ["dev"]
}
]
}
但我收到以下错误:
C:\Program Files\nodejs\node.exe .\node_modules\.bin\netlify dev
Uncaught c:\Users\kylemit\Documents\code\netlify-func\node_modules\.bin\netlify:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
^^^^^^^

SyntaxError: missing ) after argument list
<node_internals>/internal/modules/cjs/loader.js:991
Process exited with code 1
Node --inspect有很多利用 --inspect switch` 的例子。对于 Node ,但我不知道如何让它与 VS 代码断点一起工作。
其他主题
  • Any way to debug functions? #409
  • Netlify Dev functions - debugging and other issues
  • Running netlify functions in a debugger
  • Debug lambda functions locally #71
  • Debugging help / using --inspect flag throws "error : unknown option" #148
  • Debug netlify lambda functions
  • 最佳答案

    来自泰森马塔尼奇 any way to debug functions? ,您可以执行以下操作:
    包.json

    {
    "scripts": {
    "debug": "netlify dev --inspect",
    }
    }
    启动文件
    {
    "version": "0.2.0",
    "configurations": [
    {
    "name": "Launch Node",
    "type": "pwa-node",
    "request": "launch",
    "runtimeArgs": ["run-script", "debug"],
    "runtimeExecutable": "npm",
    "skipFiles": ["<node_internals>/**"]
    }
    ]
    }
    Example Screenshot

    关于node.js - 在 VS Code 中调试 Netlify 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63864022/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com