Closed ugobey closed 6 months ago
Unbelievable
https://npmfs.com/package/formidable/3.5.1/dist/index.cjs#L1682 the exported default is a function
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` });
Using the following command to import can solve the problem, and I don't know why
const {formidable} = require("formidable");
Have the same problem.
const {formidable} = require("formidable");
helped me too, i think it mey be problem with @types/formidable
Same problem here
That solved it for me thanks everyone!
Is everyone having this issue using Typescript ?
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
Im not using Typescript and have that issue but solved from the suggestion above
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.
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?
Support plan
Context
What are you trying to achieve or the steps to reproduce?
I simply upgraded to V3 and now get an error of "formidable is not a function". Im using
const formidable = require("formidable");
not import as I am not using a module and to change it is a huge hassle as it affects loads of other things.What was the result you got?
"formidable is not a function"
What result did you expect?
for it to work like it did in V2