在react-native代码中导入pg

问题描述 投票:0回答:1

作为

react-native
的新手,我正在尝试从我的
postgreSQL
应用程序连接
react-native
。我已在我的
pg
应用程序上使用此
npm install pg --save
命令安装了
react-native
模块。但是,如果我尝试在我的
pg
(根组件或任何类组件)上导入
App.js
,我会收到以下错误:

导入语法:(只是尝试了不同的语法)

  • import { Pool, Client } from 'pg';
  • import pg from 'pg';
  • import * as pg from 'pg';

错误:

错误:捆绑失败:错误:无法从

util
解析模块
<REACT_APP_PATH>/node_modules/pg/lib/index.js
:模块映射中不存在模块

注意:

const { Pool, Client } = require('pg');
语法在
node + express
应用程序中运行良好。

问题: 下面哪个是一个非常好的解决方案,为什么?

  1. 使用
    pg
    作为
    npm
    模块并导入
    react-naive
    应用程序并连接到 postgreSQL 并访问表?

    1. 如何在 `ios` 或 `android` build\package 上导入 `pg` 模块?
    2. `android/ios`有没有原生的 ode lib\module 来连接可以被`react-native`访问的`pg`?

  2. 使用node+express API服务并在fetch (axios like module)的帮助下从
    react-native
    应用程序连接它?

node.js postgresql reactjs react-native node-postgres
1个回答
0
投票

pg 库并不打算直接从 React Native 连接到 postgreSQL。

© www.soinside.com 2019 - 2024. All rights reserved.