nuxt / nuxt

The Intuitive Vue Framework.
https://nuxt.com
MIT License
53.11k stars 4.87k forks source link

bug on server/api side. #12686

Closed andysay closed 2 years ago

andysay commented 2 years ago

Environment


Describe the bug

bug only on dev mode. build woking fine.

i have next method.

axios.post("/api/upload", formData, { headers: { "Content-Type": "multipart/form-data", }, });

formData have binary data.

on server

    const uploadFolder = path.resolve('images')
    const form = formidable.IncomingForm();
    form.uploadDir = uploadFolder;

    form.parse(req, async (err, fields, files) => {
    console.log(fields);
    console.log(files);
    if (err) {
        console.log("Error parsing the files");
        }
    // Check if multiple files or a single file

    });

ERROR [proxy] write EPIPE 10:14:03

at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:98:16)

if server build and started will work fine.

Reproduction

not have

Additional context

No response

Logs

No response

danielroe commented 2 years ago

Would you provide a reproduction please? 🙏

bfg-coding commented 2 years ago

@danielroe I can provide an example as I ran into this same issue

Client

const fd = new FormData();
    fd.append("name", fileName);
    fd.append("image", file);

    axios.post("/api/avatars", fd, {
      headers: {
        'accept': 'application/json',
        'Accept-Language': 'en-US,en;q=0.8',
        'Content-Type': `multipart/form-data; boundary=${file._boundary}`,
      }
    }).then(resp => { console.log(resp)});

Nuxt3 server/api/avatars

import {IncomingMessage, ServerResponse} from "http";
import formidable from "formidable";

const form = new formidable.IncomingForm();

export default async (req: IncomingMessage, res: ServerResponse) => {
    form.parse(req, async (err, fields, files) => {
        console.log(err);
        console.log(fields);
        console.log(files);
    })
    res.end("Got data");
}

The error

 ERROR  [proxy] write EPIPE                                                                                                                                                                                                                                                                                                                                                                                                                                    

  at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:98:16)

This code does work when the project is build using nuxt3 build script nuxi build and running npm start but will not work while using nuxi dev

andysay commented 2 years ago

@danielroe I can provide an example as I ran into this same issue

Client

const fd = new FormData();
    fd.append("name", fileName);
    fd.append("image", file);

    axios.post("/api/avatars", fd, {
      headers: {
        'accept': 'application/json',
        'Accept-Language': 'en-US,en;q=0.8',
        'Content-Type': `multipart/form-data; boundary=${file._boundary}`,
      }
    }).then(resp => { console.log(resp)});

Nuxt3 server/api/avatars

import {IncomingMessage, ServerResponse} from "http";
import formidable from "formidable";

const form = new formidable.IncomingForm();

export default async (req: IncomingMessage, res: ServerResponse) => {
    form.parse(req, async (err, fields, files) => {
        console.log(err);
        console.log(fields);
        console.log(files);
    })
    res.end("Got data");
}

The error

 ERROR  [proxy] write EPIPE                                                                                                                                                                                                                                                                                                                                                                                                                                    

  at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:98:16)

This code does work when the project is build using nuxt3 build script nuxi build and running npm start but will not work while using nuxi dev

yes approve it ! works only on build state.

multiplehats commented 2 years ago

Can confirm I run into the exact same issue.

madebyfabian commented 1 year ago

I ran into exactly this issue today, how did you resolve this?

manniL commented 1 year ago

I ran into exactly this issue today, how did you resolve this?

Provide a reproduction and there might be an answer to this question 😄

madebyfabian commented 1 year ago

@manniL Thanks for getting back on this, I've just found a solution at another issue https://github.com/unjs/h3/issues/43#issuecomment-1069225214. Would have provided one otherwise :)

manniL commented 1 year ago

Great to hear ☺️