multer icon indicating copy to clipboard operation
multer copied to clipboard

Getting ERR_REQUIRE_ESM with v2.0.0-rc.4

Open sreenath-n opened this issue 2 years ago • 1 comments

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

sreenath-n avatar May 27 '22 10:05 sreenath-n

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!

LinusU avatar May 27 '22 10:05 LinusU