multer.js
const multer = require("multer");
const upload = multer().single("avatar");
module. Exports = { upload };
const { upload } = require("../middleware/multer");
router.route("/register").post(upload, registerUser);
const catchAsyncError = require("../../middleware/catchAsyncError");const ErrorHandler = require("../../utils/errorhandler");const cloudinary = require("cloudinary").v2;
// Register a userexports.registerUser = catchAsyncError(async (req, res, next) => {console.log(req.body);console.log(req.file);});
尝试修改模块。导出到module.exports并且 const upload = multer().single("avatar"); 可以改为 const upload = multer.single("avatar"); 希望这有效