Node:fs package

Site Name: https://angry-heyrovsky-52f67d.netlify.app
Build Log: Netlify App

I use NextJS, and there I have an API to upload a file which is then saved using formidable. But when I send a POST request to this endpoint, it throws a bad gateway but when I go to it normally, it says it can’t find the node:fs module.

https://angry-heyrovsky-52f67d.netlify.app/api/uploadFile

{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'node:fs'\nRequire stack:\n- /var/task/nextPage/pages/api/uploadFile.js\n- /var/task/next_api_uploadFile.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js","trace":["Runtime.ImportModuleError: Error: Cannot find module 'node:fs'","Require stack:","- /var/task/nextPage/pages/api/uploadFile.js","- /var/task/next_api_uploadFile.js","- /var/runtime/UserFunction.js","- /var/runtime/index.js","    at _loadUserApp (/var/runtime/UserFunction.js:100:13)","    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)","    at Object.<anonymous> (/var/runtime/index.js:43:30)","    at Module._compile (internal/modules/cjs/loader.js:999:30)","    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)","    at Module.load (internal/modules/cjs/loader.js:863:32)","    at Function.Module._load (internal/modules/cjs/loader.js:708:14)","    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)","    at internal/main/run_main_module.js:17:47"]}

On my localhost everything works fine.

I have NodeJS v16, and the build log says so

10:11:55 AM: v16.13.1 is already installed.
10:11:56 AM: Now using node v16.13.1 (npm v8.1.2)

Functions use a different Node version. It’s logged in there:

But if I recall correctly, we usually import fs as const fs = require('fs'), correct?

Yes but i’m using formidable (formidable/PersistentFile.js at master · node-formidable/formidable · GitHub)

Did you try changing the Node Version as described? If it’s still not working, do you have a repo to share?

Yes, but not working.

Repo:

I am trying the repo with the latest version of the Nextjs plugin (version 4) and i don’t see the function being generated anymore.

Could you try to see if that version fixes anything for you?

How do I install this version? And alternatively, have you tried opening that endpoint uploadFile? Because that page builds normally, but then when you go GET to that endpoint, it throws that error.


Do you know how I could possibly speed up the build? This will quickly use up my 300 minute capacity.

Hi @xHyroM ,

To install the new version, please see our forums post announcing the new release here.

Also, we tried to repro the issue here, but the site fails due to a client-side error. Could you let us know how to work-around that please?