Netlify site: https://bt-platform.netlify.app/
We have a Nextjs API that accepts a file in the body and parses it via formidable (which is in our
package.json). Everything is working great locally.
Here’s the api code:
import formidable, { File } from 'formidable';
//^ throws error
import type { NextApiRequest, NextApiResponse } from 'next';
export const config = { api: { bodyParser: false } };
export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
console.log("never get's executed");
const form = new formidable.IncomingForm();
// ... form parsing code
}
Our console.logs never get run, so it looks like it’s erroring immediately when the function is invoked.
We get the following error from the netlify logs:
Nov 2, 01:40:13 PM: edc7c92f ERROR Error: Cannot find module 'formidable’Nov 2, 01:40:13 PM: edc7c92f ERROR Require stack:Nov 2, 01:40:13 PM: edc7c92f ERROR - /var/task/.next/server/pages/api/content/[contentId]/files/upload.jsNov 2, 01:40:13 PM: edc7c92f ERROR - /var/task/node_modules/next/dist/server/next-server.jsNov 2, 01:40:13 PM: edc7c92f ERROR - /var/task/.netlify/functions-internal/_api_content_contentId-PARAM_files_fileId-PARAM-handler/handlerUtils.jsNov 2, 01:40:13 PM: edc7c92f ERROR - /var/task/.netlify/functions-internal/_api_content_contentId-PARAM_files_fileId-PARAM-handler/_api_content_contentId-PARAM_files_fileId-PARAM-handler.jsNov 2, 01:40:13 PM: edc7c92f ERROR - /var/task/_api_content_contentId-PARAM_files_fileId-PARAM-handler.jsNov 2, 01:40:13 PM: edc7c92f ERROR - /var/runtime/index.mjsNov 2, 01:40:13 PM: edc7c92f ERROR at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)Nov 2, 01:40:13 PM: edc7c92f ERROR at Function.mod._resolveFilename (/var/task/node_modules/next/dist/build/webpack/require-hook.js:27:32)Nov 2, 01:40:13 PM: edc7c92f ERROR at Function.Module._load (node:internal/modules/cjs/loader:778:27)Nov 2, 01:40:13 PM: edc7c92f ERROR at Module.require (node:internal/modules/cjs/loader:1005:19)Nov 2, 01:40:13 PM: edc7c92f ERROR at require (node:internal/modules/cjs/helpers:102:18)Nov 2, 01:40:13 PM: edc7c92f ERROR at Object.2616 (/var/task/.next/server/pages/api/content/[contentId]/files/upload.js:39:18)Nov 2, 01:40:13 PM: edc7c92f ERROR at webpack_require (/var/task/.next/server/webpack-api-runtime.js:25:42)Nov 2, 01:40:13 PM: edc7c92f ERROR at Object.7455 (/var/task/.next/server/pages/api/content/[contentId]/files/upload.js:72:68)
Have tried the following:
- empty cache and rebuild on netlify
- delete yarn.lock and regenerate it via
yarn
- explicitly set our NODE_VERSION to be the same as local
Any ideas? The build process seems to be working and installing okay.