Skip to content

Multer 2.0 doesn't work with Node.js 16.0 due to semver-major upgrade #995

@pubmikeb

Description

@pubmikeb

For file uploading to the cloud, I'm using Multer ("multer": "^2.0.0-rc.2"). With Node.js 15.3.0 everything is working great, after upgrading to 16.0.0 (starting end of March 2021) I'm getting the following error:

node:internal/process/promises:245
          triggerUncaughtException(err, true /* fromPromise */);
          ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received null
    at TempWriteStream.WriteStream (node:internal/fs/streams:360:5)
    at new TempWriteStream (C:\Users\User\IdeaProjects\TMS\node_modules\fs-temp\lib\write-stream.js:6:15)
    at Object.createWriteStream (C:\Users\User\IdeaProjects\TMS\node_modules\fs-temp\lib\temp.js:121:10)
    at Busboy.<anonymous> (C:\Users\User\IdeaProjects\TMS\node_modules\multer\lib\read-body.js:70:27)
    at Busboy.emit (node:events:369:20)
    at Busboy.emit (C:\Users\User\IdeaProjects\TMS\node_modules\busboy\lib\main.js:37:33)
    at PartStream.<anonymous> (C:\Users\User\IdeaProjects\TMS\node_modules\busboy\lib\types\multipart.js:214:13)
    at PartStream.emit (node:events:369:20)
    at HeaderParser.<anonymous> (C:\Users\User\IdeaProjects\TMS\node_modules\dicer\lib\Dicer.js:50:16)
    at HeaderParser.emit (node:events:369:20) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Process finished with exit code 1

When I'm rolling back to 15.3.0 no error occurs.
After some investigation, I've found out that the source of the issue is await asyncUpload(req, res);.
The code snippet:

const _upload = multer({
	limits: {
		fileSize: CONFIG_STORAGE.uploader.maxFileSizeInBytes
	}
}).single("file");

const asyncUpload = promisify(_upload);
await asyncUpload(req, res);

At Node.js thread I've got a response that the change nodejs/node#35187 has broken some compatibility and Multer has to be adjusted to be able to work with Node.js 16.0+

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions