multer
multer copied to clipboard
Getting ERR_REQUIRE_ESM with v2.0.0-rc.4
Node Version v16.15.0
v2.0.0-rc.4 has this error, but v1.4.4 doesn't have this error
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/nodejs/project1/node_modules/multer/index.js from /Users/nodejs/project1/src/api/files/files.routes.js not supported.
Instead change the require of index.js in /Users/nodejs/project1/src/api/files/files.routes.js to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (/Users/nodejs/project1/src/api/files/files.routes.js:3:16)
at setupRoutes (/Users/nodejs/project1/src/index.js:81:27)
at main (/Users/nodejs/project1/src/index.js:18:15) {
code: 'ERR_REQUIRE_ESM'
}
files.routes.js
const express = require('express')
const filesController = require('./files.controller')
const multer = require('multer')
const upload = multer({ dest: 'uploads' })
const router = express.Router()
router.post('/upload', upload.single('file'), filesController.upload)
router.get('/download/:filename', filesController.download)
module.exports = router
This is discussed in #1042, one of our dependencies is ESM only and thus we are also ESM only.
Version 2.x also has a new different API so you'll probably have to make quite some changes if your code based was built on top of 1.x.
We really need to make a good migration guide before releasing 2.x stable. If anyone could help with this that would be awesome!