expressjs/multer

Getting ERR_REQUIRE_ESM with v2.0.0-rc.4

Open

#1100 opened on May 27, 2022

View on GitHub
 (1 comment) (0 reactions) (0 assignees)JavaScript (11,136 stars) (1,043 forks)batch import
help wanted

Description

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

Contributor guide