Ok, I have switched to esbuild. I’m not sure about the configuration though.
With netlify-lambda, I followed the docs and this is what I did:
netlify.toml:
[build]
command = "npm run build"
functions = "lambda"
publish = "build"
package.json
"build:lambda": "netlify-lambda build src/utilities/lambda --config ./webpack.lambda.js",
"debug": "netlify dev --inspect"
webpack.lambda.js
module.exports = {
optimization: {minimize: false},
devtool: "source-map",
target: "node",
}
This all worked for me as explained in the netlify-lambda docs.
How can I do this with esbuild? I removed from all the code everything that is netlify-lambda specific to make sure I didn’t have unnecessary code. (including functions = "lambda"
, I don’t see a function
property mentioned outside of the netlify-lambda docs.
Then I added:
[functions]
node_bundler = "esbuild"
According to the docs:
The following property applies for all Netlify Functions:
directory: a custom path to your serverless functions. The default location is YOUR_BASE_DIRECTORY/netlify/functions
So I added this to netlify.toml under functions
directory = "src/utilities/lambda/"
With this config, Netlify Dev works. But it won’t let me step through the code like when I used netlify-lambda. A source map issue?
This was my vscode configuration that worked with netlify-lambda?
{
"version": "0.2.0",
"configurations": [
{
"name": "Netlify Debugging",
"type": "pwa-node",
"request": "launch",
"program": "${workspaceFolder}\\node_modules\\.bin\\netlify",
"runtimeArgs": [
"run-script",
"debug"
],
"runtimeExecutable": "npm",
"skipFiles": [
"<node_internals>/**"
],
"sourceMapPathOverrides": {
"webpack:///./*": "${workspaceFolder}/src/utilities/lambda/*",
},
"resolveSourceMapLocations": [
"${workspaceFolder}/**",
"!**/node_modules/**"
]
}
]
}
What do I need to change?
Also, although the function is working with Netlify Dev, it’s not being included in the production build. “npm run build” doesn’t build the function.
Lastly, just FYI when I run netlify dev, the function is being built here:
.netlify\functions-serve\apiRequest\src\netlify\functions\