Coder Social home page Coder Social logo

Comments (12)

Sumzibuyu avatar Sumzibuyu commented on June 5, 2024 2

Using the following command to import can solve the problem, and I don't know why
const {formidable} = require("formidable");

from formidable.

GrosSacASac avatar GrosSacASac commented on June 5, 2024

Unbelievable

from formidable.

GrosSacASac avatar GrosSacASac commented on June 5, 2024

https://npmfs.com/package/formidable/3.5.1/dist/index.cjs#L1682
the exported default is a function

from formidable.

ugobey avatar ugobey commented on June 5, 2024

And yet when I revert to V2 it works and simply upgrade to V3 again it fails with same error which makes no sense I agree but its happening

const formidable = require("formidable");

app.post("/upload", (req, res, next) => {
        const form = formidable({ multiples: true, uploadDir: `${__dirname}/upload` });

        form.parse(req, (err, fields, files) => {
            if (err) {
                next(err);
                return;
            }

            var file = files.file.filepath;
            var mimetype = files.file.mimetype;

            if (mimetype === "image/png" || mimetype === "image/jpeg") {
                Jimp.read(file)
                    .then(async (logo) => {
                        await logo.resize(48, 48).quality(100).writeAsync(`${__dirname}/output/icon.png`);

                        var getNewFile = fs.readFileSync(`${__dirname}/output/icon.png`, "base64");

                        fs.unlinkSync(file);
                        fs.unlinkSync(`${__dirname}/output/icon.png`);

                        res.end(getNewFile);
                    })
                    .catch((err) => {
                        errorHandler("Error : Jimp : " + err);
                    });
            } else {
                fs.unlinkSync(file);
                res.end("WRONG MIMETYPE");
            }
        });
    });

It fails at line

const form = formidable({ multiples: true, uploadDir: `${__dirname}/upload` });

from formidable.

crowmw avatar crowmw commented on June 5, 2024

Have the same problem.
const {formidable} = require("formidable");
helped me too, i think it mey be problem with @types/formidable

from formidable.

RoseannePeeters avatar RoseannePeeters commented on June 5, 2024

Same problem here

from formidable.

ugobey avatar ugobey commented on June 5, 2024

That solved it for me thanks everyone!

from formidable.

GrosSacASac avatar GrosSacASac commented on June 5, 2024

Is everyone having this issue using Typescript ?

from formidable.

RoseannePeeters avatar RoseannePeeters commented on June 5, 2024

Is everyone having this issue using Typescript ?

No I am not

This works though:

Have the same problem. const {formidable} = require("formidable"); helped me too, i think it mey be problem with @types/formidable

from formidable.

ugobey avatar ugobey commented on June 5, 2024

Im not using Typescript and have that issue but solved from the suggestion above

from formidable.

tunnckoCore avatar tunnckoCore commented on June 5, 2024

That's normal. It's a SemVer Major release, and it's documented. We tried to have backwards compat but yeah.

We have exports.default, but i think we should also have module.exports for all that to work "properly".. in general, i think we can safely drop CJS for v4.

from formidable.

Gin49SZ avatar Gin49SZ commented on June 5, 2024

Using the following command to import can solve the problem, and I don't know why const {formidable} = require("formidable");

I meet the same problem, does it affect any subsequent code?

from formidable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.