After having issues with using the old netlify-lambda, I finally decided to switch to having netlify dev handle building of our node.js functions that use ES imports and plain javascript.
We are using a custom build step that we need to save a build-time environment variable.
Running netlify dev
for local development correctly identifies the lambda functions, but incorrectly tries to run the “build” script even though I’m not executing netlify build
. Besides building the project when it shouldn’t, it then stalls at Waiting for framework port 3000. This can be configured using the 'targetPort' property in the netlify.toml
and then ends with "npm run build" exited with code 0. Shutting down Netlify Dev server
.
I’ve got these scripts in our package.json:
"start": "netlify dev",
"build": "npm run gen:build-token && run-p build:**",
"build:app": "react-scripts build",
"gen:build-token": "sed -i_backup -E s/BUILD_TOKEN_PLACEHOLDER/${COMMIT_REF}/g src/lambda/utils/commonResponses.js",
Our netlify.toml looks like this:
[build]
command = "npm run build"
functions = "src/lambda/"
publish = "build"
AWS_LAMBDA_JS_RUNTIME = "nodejs16.x"
[functions]
node_bundler = "esbuild"