简体   繁体   中英

"The "path" argument must be string. Received undefined"how do I resolve this error

In my project that I developed with node js, I get the error "TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be string. Received undefined". Can you help me?

some of the codes:

router.post('/test', (req,res) =>{

   const post_image = req.files.post_image.name

   post_image.mv(path.resolve(__dirname, '../public/img/postimages', post_image.name))

   Post.create(req.body)
   console.log(req.files.post_image.name)
   res.redirect("/")
})

I think the error may be caused by the code in third line because when you make it a comment line, the error disappears.

_dirname or post_image.name must be undefined. Check all the arguments of path.resolve() function are defined and string

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM