Nextjs Deployment with "functions" folder

Hey! I have been using vercel for sometime for my nextjs website and it’s great. However, I just found out that they don’t allow commercial sites in the free plan So I had to move to netlify which in my opinion is equally great. My nextjs website uses firebase functions among other things and so I have a created a functions folder in the root directory which is a common thing to do. But when i deploy it on netlify, It throws some erroe because of it. My website deploy fine when I remove or rename the folder. From what I know, I think netlify creates and uses the “functions” directory to store some stuff which doesn’t play well with all the stuff that’s already there. Here’s the Error I am getting:

9:38:10 AM: ────────────────────────────────────────────────────────────────
9:38:10 AM:   Dependencies installation error                               
9:38:10 AM: ────────────────────────────────────────────────────────────────
9:38:10 AM: ​
9:38:10 AM:   Error message
9:38:10 AM:   A Netlify Function is using "@kubernetes/client-node" but that dependency has not been installed yet.
9:38:10 AM: ​
9:38:10 AM:   By default, dependencies inside a Netlify Function's "package.json" are not automatically installed.
  There are several ways to fix this problem:
9:38:10 AM:     - Removing your Function's "package.json" and adding the dependencies to the project's top-level "package.json" instead. This is the fastest and safest solution.
9:38:10 AM:     - Running "npm install" or "yarn" inside your Netlify Function in your build command.
9:38:10 AM:     - Adding the following plugin to your "netlify.toml":
9:38:10 AM: ​
9:38:10 AM:   [[plugins]]
9:38:10 AM:   package = "@netlify/plugin-functions-install-core"
9:38:10 AM: ​​
9:38:10 AM:   In file "/opt/build/repo/functions/index.js"
9:38:10 AM:   Cannot find module '@kubernetes/client-node'
9:38:10 AM:   Require stack:
9:38:10 AM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/bundlers/zisi/resolve.js
9:38:10 AM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/bundlers/zisi/traverse.js
9:38:10 AM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/bundlers/esbuild/src_files.js
9:38:10 AM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/bundlers/esbuild/index.js
9:38:10 AM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/bundlers/index.js
9:38:10 AM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/index.js
9:38:10 AM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/index.js
9:38:10 AM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/main.js

Also one thing to note here is that the functions folder contains npm_modules and nodejs functions because firebase function supports nodejs runtime.

In most cases, you don’t need this.

Rather you should add this dependency to your top-level package.json.

About this, I’m not quite sure I understand. You don’t need to have node_modules folder in your repo and I am not sure how it relates to Firebase Functions supporting Node.js runtime. Could you please elaborate?

What I mean here is that firebase functions run on Nodejs, so it’s like a different JS project inside the functions directory. And this may create problems with Netlify that’s installing its own JS packages like the k8s client in the same directory. Is there a way by which I can hide this directory from Netlify?

You can specify a different Functions directory for Netlify and then Netlify would ignore the one used by Firebase. So, you could simply point your Functions folder to a non-existent directory and that would work too.

I just want to say that it’s so confusing and makes no sense to make use of this directory. I mean functions is a common folder name people usually have in their project. why would you use choose such a common name in the first place and you shouldn’t even be writing over the project either. And if you guys are really using this at least change the directory name to something unique when you see that a directory named functions already exists.
Anyways could you tell me how do I point my already existing functions folder to some other place?

1 Like

I get that it’s frustrating for you, but that also makes it easier for so many users of Netlify Functions - simply create a folder named functions, write your code in it and Netlify automatically deploys it. I understand that’s not what you’d want to happen, but a lot of people want that to happen. So, from our point of view, it does make sense to use this directory.

You can change the directory name here:<site-name>/settings/functions#settings

Okay, I get your point now and I think it makes sense. I was a long-time Vercel & Nextjs user and that’s why I didn’t understand why you implement it that way. Thanks for the help.

1 Like