expressjs/multer

Getting ERR_REQUIRE_ESM with v2.0.0-rc.4

Open

#1100 aperta il 27 mag 2022

Vedi su GitHub
 (1 commento) (0 reazioni) (0 assegnatari)JavaScript (1043 fork)batch import
help wanted

Metriche repository

Star
 (11.136 star)
Metriche merge PR
 (Merge medio 9g 11h) (7 PR mergiate in 30 g)

Descrizione

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

Guida contributor