【问题标题】:angular universal connected postgresql issue角度通用连接的postgresql问题
【发布时间】:2021-01-04 16:53:10
【问题描述】:

我在 Angular Universal 上 npm install pg,修改 Server.ts import pg 以连接 postgresql,npm run dev:ssr,显示这样的错误。 找不到模块:错误:无法解析 'D:\gitapp\ngex\node_modules\pg\lib\native' 中的 'pg-native' 解决 'D:\gitapp\ngex\node_modules\pg\lib\native' 中的 'pg-native' , 我尝试 npm install pg-native ,但无法成功。 但如果在纯打字稿上 express 并连接 pg ,则没有错误。

 import * as pg from 'pg';
const config = { 
    host: '192.168.0.1', 
    user:"postgres",
    database:"pgdata",
    password:"pg123456",
    port:5432,
     max:20,
    idleTimeoutMillis:3000,
   };
   const pool = new pg.Pool(config); 

【问题讨论】:

    标签: angular postgresql universal


    【解决方案1】:

    已经解决了,我只是在 github 上检查了 angular Universal,有人也有这个问题,要解决这个问题,你可以使用 externalDependencies 选项。可以在angular.json中配置。"server": { "builder": "@angular-devkit/build-angular:server", "options": { "outputPath": "dist/server", "main": "server.ts", "tsConfig": "tsconfig.server.json", "externalDependencies": [ "pg" ] }, ... }

    【讨论】:

      猜你喜欢
      • 2021-11-18
      • 2011-04-10
      • 2011-07-28
      • 2016-01-14
      • 1970-01-01
      • 1970-01-01
      • 2017-03-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多