question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Formidable and form packages

See original GitHub issue

Bug report

Describe the bug

I was on Next.js v8 with a monorepo, but am now upgrading to v9 with all endpoints moved to the new pages/api/ feature. But now any of my post endpoints that include file uploading do not work. I tried to simplify the reproduction as much as possible, not even worrying about the API endpoint resolving.

The problem is that the Formidable parse never seems to finish. I also tried Tim’s urlencoded-body-parser as alternative, but it seems to hang also.

A clear and concise description of what the bug is.

To Reproduce

Micro endpoint in pages/api/endpoint.js:

const { run } = require("micro");
const formidable = require("formidable");

const endpoint = async (req, res) => {
  const data = await new Promise(function(resolve, reject) {
    const form = new formidable.IncomingForm();

    form.parse(req, function(err, fields, files) {
      if (err) return reject(err);
      resolve({ fields, files });
    });
  });
};

module.exports = (req, res) => run(req, res, endpoint);

Client-side post in pages/index.js:

const response = await fetch(url, {
  body,
  credentials: "include",
  headers: {
    Authorization: JSON.stringify({ token })
  },
  method: "POST"
});

Expected behavior

That the parse would finish and data would be assigned.

Screenshots

Screen Shot 2019-07-13 at 5 10 11 PM

System information

  • OS: macOS
  • Browser: Chrome
  • Version of Next.js: 9.0.1

Additional context

Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

12reactions
synccommented, Jul 13, 2019

i think you need to add to pages/api/endpoint.js:

export const config = {
  api: {
    bodyParser: false,
  },
};
0reactions
balazsorban44commented, Jan 29, 2022

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Formidable - npm
A Node.js module for parsing form data, especially file uploads. Code style codecoverage linux build status windows build status macos build ...
Read more >
Formidable Forms - The Most Advanced WordPress Forms ...
Formidable Forms is the best WordPress forms plugin. Over 300000 professionals use our WordPress form builder to create contact forms, surveys, calculators, ...
Read more >
Formidable Forms Pricing, Packages & Plans 2022 - G2
Formidable Forms Pricing ; Lite. $0.00. Build beautiful contact forms with all the basic fields. Unlimited forms; Unlimited users; Unlimited form ...
Read more >
Formidable and form packages #7947 - vercel/next.js - GitHub
Bug report Describe the bug I was on Next.js v8 with a monorepo, but am now upgrading to v9 with all endpoints moved...
Read more >
Uploading Files using Formidable in a Node.js Application
As mentioned previously, formidable is a Node.js module for parsing form data, especially file uploads. Let's start by installing formidable.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found