Problem switching from netlify-lambda to netlify dev

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:

  command = "npm run build"
  functions = "src/lambda/"
  publish = "build"
  AWS_LAMBDA_JS_RUNTIME = "nodejs16.x"

  node_bundler = "esbuild"

What happens when you add:

  command = "npm run dev" # or whatever your command is

in your netlify.toml?

There’s no command “dev” and accordingly npm fails with “Missing script: “dev””.
What do you mean by “whatever your command is”? The command is “netlify dev”. It supposedly should detect that I have a create-react-app project with lambda functions and build it accordingly.

Okay, nevermind. It seems to be working now even though I didn’t change anything in the project. Maybe upgrading to netlify-cli 16 is what solved it.