【问题标题】:Heroku : Cannot find module 'pg'?Heroku:找不到模块'pg'?
【发布时间】:2021-06-17 01:49:22
【问题描述】:

2021-03-19T16:05:15.937220+00:00 app[web.1]:错误:找不到模块“pg”

2021-03-19T16:05:15.937220+00:00 app[web.1]:需要堆栈:

2021-03-19T16:05:15.937220+00:00 app[web.1]: - /app/models/db_schema.js

2021-03-19T16:05:15.937221+00:00 app[web.1]: - /app/controllers/event_controller.js

2021-03-19T16:05:15.937221+00:00 app[web.1]: - /app/router/event_routes.js

2021-03-19T16:05:15.937221+00:00 app[web.1]: - /app/app.js

这是我的 package.json

{

“名称”:“后端”,

“版本”:“1.0.0”,

“描述”:“”,

"main": "app.js",

“引擎”:{

"node": "v14.12.0",

"npm": "6.14.8"

},

“脚本”:{

"test": "echo \"Error: no test specified\" && exit 1",

"start": "node app.js",

"start:dev": "nodemon app.js",

"heroku-postbuild": "cd frontend && npm install && npm run build"

},

“存储库”:{

"type": "git",

"url": "git+https://github.com/shivamsouravjha/shawn-the-sheep.git"

},

“作者”:“shivam”,

“许可证”:“ISC”,

“错误”:{

"url": "https://github.com/shivamsouravjha/shawn-the-sheep/issues"

},

“主页”:“https://github.com/shivamsouravjha/shawn-the-sheep#readme”,

“devDependencies”:{

"nodemon": "^2.0.7",


"pg": "^8.5.1",

"router": "^1.3.5"

},

“依赖”:{

"cors": "^2.8.5",

"dotenv": "^8.2.0",

"express": "^4.17.1",

"express-validator": "^6.10.0"

}

}

【问题讨论】:

  • 你的 procfile 里有什么?
  • web: node app.js 但我安装了 Postgres 文件依赖项,我可以通过命令提示符(heroku postgres 的东西)放置数据并显示在我的 PGAdmin4 中
  • @JoshieWahWah 上面的评论是给你的朋友
  • 我刚从公园回家。您的节点模块是否与您的入口文件位于同一目录中? /node_modules/ 例如与 app.js 在同一目录中。
  • 希望您精神焕发 :-) ,node_module 文件夹在它应该在的地方。这是 github repo 的链接,供您试用github.com/shivamsouravjha/shawn-the-sheep@JoshieWahWah

标签: node.js postgresql heroku module


【解决方案1】:

所以文件结构是:

/应用程序

----app.js

----node_modules/

还需要将 pg 从 devDependencies 移动到 Dependencies 并运行 npm run build。

【讨论】:

    猜你喜欢
    • 2015-10-21
    • 2015-09-21
    • 1970-01-01
    • 2016-07-31
    • 2016-09-05
    • 1970-01-01
    • 2011-12-13
    • 1970-01-01
    相关资源
    最近更新 更多