---
# System prepended metadata

title: '後端部署到heroku上跳出 Error: Cannot f'

---

後端部署到heroku上跳出 Error: Cannot find module 'dotenv'

![](https://hackmd.io/_uploads/rJZGSUMa3.png)


![](https://hackmd.io/_uploads/Hy2BBIGTn.png)


![](https://hackmd.io/_uploads/S1cDBIfp3.png)


postman畫面：

![](https://hackmd.io/_uploads/HJ53SLzan.png)


![](https://hackmd.io/_uploads/H1ICHUf63.png)


如果用http://localhost:3000 是可以順利拿到資料的

![](https://hackmd.io/_uploads/SysML8zph.png)


## 確認過:

### 1. heroku api 連結格式正確
https://devcenter.heroku.com/articles/heroku-connect-api

![](https://hackmd.io/_uploads/Bycj8Uzph.png)


### 2. CLI中的確有dotenv

![](https://hackmd.io/_uploads/rk2Dv8GT2.png)

### 3. 如果下指令：npm install dotenv --save

dotenv會從package.json中消失
![](https://hackmd.io/_uploads/HJ3awLG62.png)

### 4. 把package-lock.json和node_modules刪除之後重新安裝，並執行 npm install dotenv --save

dotenv還是會從package.json中消失


### 5. 參考文章：
https://bobbyhadz.com/blog/node-cannot-find-module-dotenv

https://stackoverflow.com/questions/65685282/error-while-deploying-node-js-application-to-heroku-cannot-find-module-dotenv

