Netlify functions are crashing because of some unknown module error

Hello Team,

I am running into an runtime error in netlify function which causes functions to completely crash and it does not recover again. Application builds just fine but when I call a particular function, it results in below error.

I know it is related to the some module resolution, but I have no way to know. Function simple crash and do not recover. Error seems to be esbuild related but I am not sure what.

I have attached the full log and my netlify.toml file.

  directory = './server/functions/'
  included_files = ["server/**/*.*","services/**/*.*"]
  node_bundler = "esbuild"
  external_node_modules = ["axios"]

Here is the complete log:

Your project seems to use Netlify CLI v12 as a dependency. Have you tried upgrading to the latest version?

Thanks @hrishikesh . I did the update… One good news and one bad news.

  • whole function is working fine and returning the correct status code. Thank you.

But the function server is still going down with below cryptic error:

 ›   Error: Netlify CLI has terminated unexpectedly
This is a problem with the Netlify CLI, not with your application.
If you recently updated the CLI, consider reverting to an older version by running:

npm install -g netlify-cli@VERSION

You can use any version from

Please report this problem at including the error details below.

Response with status 200 in 526 ms.
Error: the worker thread exited
    at Worker.onWorkerExit (/Users/jatinkathuria/experiments/mf-next/node_modules/thread-stream/index.js:180:32)
    at Worker.emit (node:events:517:28)
    at Worker.emit (node:domain:489:12)
    at Worker.[kOnExit] (node:internal/worker:289:10)
    at Worker.<computed>.onexit (node:internal/worker:209:20)

Edit: Happy birthday @hrishikesh :tada: :tada:


Is this happening only on your machine? Have you tried using a different device?

An update from my side. thanks for your suggestion.

The error is happening everywhere so I tried to deploy these functions on Netlify where I got to see the actual error. It would be great if we could see the actual error in dev env as well so that we need not waste build minutes on netlify. See below screenshot.

I think this error is happening is because pino-pretty is Node.js dependency and netlify functions do not use node.js as javascript engine. Is my assumption correct?

Thanks for your responses.

It’s not always possible as the dev env is very different from production. You’re talking about a local computer against a microserver that’s booted by AWS. The CLI tries to mimic, but based on how filesystems, Node.js, module resolution and other factors work, it’s simply not always going to work.

I got this error when using Fastify along with pino-pretty for logs. This is documented here: Readme ( Basically, you need:

import {cwd, env} from 'node:process'
import {join} from 'node:path'
let basePath = ''
if (env['NETLIFY_DEV'] === 'true') {
  basePath = join(cwd(), './.netlify/functions-serve/<function-name>/node_modules/')
} else {
  basePath = join(cwd(), './node_modules/')
globalThis.__bundlerPathsOverrides = {
  'pino/file': join(basePath, './pino/file.js'),
  'pino-pretty': join(basePath, './pino-pretty/index.js'),
  'pino-pipeline-worker': join(basePath, './pino/lib/worker-pipeline.js'),
  'pino-worker': join(basePath, './pino/lib/worker.js'),
  'thread-stream-worker': join(basePath, './thread-stream/lib/worker.js')

before initializing pino (in my case, Fastify) and your netlify.toml should have:

  included_files = [
  external_node_modules = [

No, Netlify Functions use Node.js. Not sure why you felt they don’t.