簡體   English   中英

““路徑”參數必須是字符串。收到未定義的“如何解決此錯誤

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

在我使用節點 js 開發的項目中,我收到錯誤“TypeError [ERR_INVALID_ARG_TYPE]:“路徑”參數必須是字符串。收到未定義”。 你能幫助我嗎?

一些代碼:

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("/")
})

我認為該錯誤可能是由第三行中的代碼引起的,因為當您將其設為注釋行時,錯誤就會消失。

_dirnamepost_image.name必須未定義。 檢查path.resolve()函數的所有參數是否已定義和字符串

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM