All next.js suddently endpoints return 500, TypeError: file.startsWith is not a function`

Hello, I have tried everything, asking the Netlify AI, looking trough posts but there seems to be no info on this leading me to believe this is a new issue from netlify with next.js

I woke up to all my next.js api calls failing with 500, and looking at the logs the only information I have is

Feb 21, 12:26:37 PM: 19ed1a8b ERROR  TypeError: file.startsWith is not a function
Feb 21, 12:26:37 PM: 19ed1a8b ERROR      at promises.readFile (/var/task/.netlify/functions-internal/___netlify-handler/handlerUtils.js:98:18)
Feb 21, 12:26:37 PM: 19ed1a8b ERROR      at promises.readFile (/var/task/.netlify/functions-internal/___netlify-handler/handlerUtils.js:98:18)
Feb 21, 12:26:37 PM: 19ed1a8b ERROR      at getSource (node:internal/modules/esm/load:43:20)
Feb 21, 12:26:37 PM: 19ed1a8b ERROR      at getSource (node:internal/modules/esm/load:43:20)
Feb 21, 12:26:37 PM: 19ed1a8b ERROR      at defaultLoad (node:internal/modules/esm/load:111:38)
Feb 21, 12:26:37 PM: 19ed1a8b ERROR      at defaultLoad (node:internal/modules/esm/load:111:38)
Feb 21, 12:26:37 PM: 19ed1a8b ERROR      at ModuleLoader.load (node:internal/modules/esm/loader:416:13)
Feb 21, 12:26:37 PM: 19ed1a8b ERROR      at ModuleLoader.load (node:internal/modules/esm/loader:416:13)
Feb 21, 12:26:37 PM: 19ed1a8b ERROR      at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:287:22)
Feb 21, 12:26:37 PM: 19ed1a8b ERROR      at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:287:22)
Feb 21, 12:26:37 PM: 19ed1a8b ERROR      at new ModuleJob (node:internal/modules/esm/module_job:63:26)
Feb 21, 12:26:37 PM: 19ed1a8b ERROR      at new ModuleJob (node:internal/modules/esm/module_job:63:26)
Feb 21, 12:26:37 PM: 19ed1a8b ERROR      at #createModuleJob (node:internal/modules/esm/loader:311:17)
Feb 21, 12:26:37 PM: 19ed1a8b ERROR      at #createModuleJob (node:internal/modules/esm/loader:311:17)
Feb 21, 12:26:37 PM: 19ed1a8b ERROR      at ModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:264:34)
Feb 21, 12:26:37 PM: 19ed1a8b ERROR      at ModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:264:34)
Feb 21, 12:26:37 PM: 19ed1a8b ERROR      at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:250:17)
Feb 21, 12:26:37 PM: 19ed1a8b ERROR      at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:250:17)
Feb 21, 12:26:37 PM: 19ed1a8b ERROR      at async ModuleLoader.import (node:internal/modules/esm/loader:335:23)
Feb 21, 12:26:37 PM: 19ed1a8b ERROR      at async ModuleLoader.import (node:internal/modules/esm/loader:335:23)

Every API works on localhost tho, only when deployed this happens

Everything worked fine last week, and no code has been updated whatsoever. Even very very simple APIs don’t work. Example.

const handler = async (req: any, res: any) => {
  console.log(req)
  console.log('Called')

  return res.status(200).json({})
}

I tried updating the dependencies but then the very well known “Invocation Failed” error happens when using 4.41.3 Next.js runtime

Using 4.41.2 produces the same error TypeError: file.startsWith is not a function

Even tried using new node version 20, same error

At the moment I use

"next": "13.4.19",
"@netlify/plugin-nextjs": "4.39.0",

Hi @msss,

Thanks for reaching out!

Could you let us know the sitename (example, sitename.netlify.app) . This will allow us to view all your deploy logs. Generally the solution is to upgrade (when using a version of Next.js below 13.5 to netlify/plugin-nextjs 4.41.3.

Thank you for the reply Melvin, our site is

We will try the solution your proposed again

Hi @msss,

Thanks for following up and providing the link.

Looking at the last few deploys, it looks like you’re using the Netlify/Next.js runtime version 4.39.0. I wasn’t able to find a deploy that used the 4.41.3 runtime. Please let us know if you continue to have this issue when using the 4.41.3: @netlify/plugin-nextjs - npm Thanks!

1 Like

Thank you very much, this has solved our issue the working dependencies combo without any errors so far is

"next": "13.4.19",
"@netlify/plugin-nextjs": "4.41.3",

Hi @msss,

Thanks for getting back to us and letting us know how you resolved this issue. I hope you have a great day!