帮我了解一下问题是什么。当我启动项目时,出现了一个错误:TypeError: registrationRules is not a function at Object.<anonymous> (C:UsersfenrirDesktopchat-appchat-backendrouterauth.js:8:4) at Module._compile (node:internal/modules/cjs/loader:1083:30) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:10) at Module.load (node:internal/modules/cjs/loader:948:32) at Function.Module._load (node:internal/modules/cjs/loader:789:14) at Module.require (node:internal/modules/cjs/loader:972:19) at require (node:internal/modules/cjs/helpers:88:18) at Object.<anonymous> (C:UsersfenrirDesktopchat-appchat-backendrouterindex.js:7:17) at Module._compile (node:internal/modules/cjs/loader:1083:30) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:10) Program node index.js exited with code 1
auth.js:
const router = require('express').Router()
const { login, register } = require('../controllers/authController')
const { validate } = require('../validators')
const { rules: registrationRules } = require('../validators/auth/register')
router.post('/login', login)
router.post('/register', [
registrationRules(),
validate
], register)
module.exports = router
register.js:
const {body} = require('express-validator')
exports.rules = () => {
return [
body('firstName').notEmpty(),
body('lastName').notEmpty(),
body('gender').notEmpty(),
body('email').isEmail(),
body('password').isLength({ min: 5})
]
}
你可以试试这个吗
const { rules as registrationRules } = require('../validators/auth/register')