node.js - 看到错误模块未找到 : 'pg-native' in heroku app

标签 node.js reactjs heroku heroku-postgres

我正在尝试将 postgres 附加组件与同样使用 React 的 heroku Node 应用程序一起使用。

我正在使用这个 React buildpack 来支持 heroku 内部的 React: https://github.com/opike/create-react-app-buildpack.git

当我尝试添加行时:

var pg = require('pg');

当我尝试在本地运行 heroku 应用程序时出现以下编译错误:

>heroku local web
[OKAY] Loaded ENV .env File as KEY=VALUE Format
[WARN] ENOENT: no such file or directory, open 'Procfile'
[OKAY] package.json file found - trying 'npm start'
4:15:19 PM web.1 |  > test-app@0.1.0 start /Users/oliverpike/dev/heroku/ofp-react
4:15:19 PM web.1 |  > react-scripts start
4:15:20 PM web.1 |  Starting the development server...
4:15:29 PM web.1 |  Failed to compile.
4:15:29 PM web.1 |  Error in ./~/pg/lib/native/index.js
4:15:29 PM web.1 |  Module not found: 'pg-native' in /Users/oliverpike/dev/heroku/ofp-react/node_modules/pg/lib/native
4:15:29 PM web.1 |   @ ./~/pg/lib/native/index.js 1:13-33
4:15:29 PM web.1 |  Error in ./~/pg/lib/connection-parameters.js
4:15:29 PM web.1 |  Module not found: 'dns' in /Users/oliverpike/dev/heroku/ofp-react/node_modules/pg/lib
4:15:29 PM web.1 |   @ ./~/pg/lib/connection-parameters.js 2:10-24

最佳答案

我通过以下方式解决了这个问题:

> npm i pg-native

如这里所述: https://github.com/brianc/node-pg-native

还有一个

> npm i dns

对于 dns 问题。

奇怪的是,我不需要在我的其他使用 postgres 的 heroku 应用程序中显式安装这些包。

关于node.js - 看到错误模块未找到 : 'pg-native' in heroku app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41528180/

相关文章:

node.js - 对电视的网络请求可从除 Raspberry Pi 以外的任何设备运行

sql-server - 在 Linux/Ubuntu 上使用 Nodejs + MSSQL

node.js - NodeJs Stream - 内存不足

ruby-on-rails - 无法在 Heroku 托管的 Postgres 数据库上运行 Ruby on Rails 测试

ruby-on-rails - 如何用 ActiveSupport::LoggerSilence 替换 LoggerSilence?

heroku - graphql Playground 在 heroku 上运行时表现异常

javascript - NodeJS + Hapi + CSS 麻烦

reactjs - react : setting up firebase auth with firebase-ui

reactjs - 根据badgeContent中的内容操纵Material UI/React Badge组件的可见性

javascript - 回流: How to listen to a subset of actions using `listanables` or `this.listenToMany` ?