【问题标题】:pg-promise TypeError: Invalid "options" parameterpg-promise TypeError:无效的“选项”参数
【发布时间】:2021-10-05 04:22:11
【问题描述】:

我正在尝试将我的文件从使用 pg 包更改为 pg-promise 包。我使用的初始pg 解决方案一切正常。但是,切换到 pg-promise 并使用文档时,我在设置过程中遇到了奇怪的错误。

最新错误:

throw new TypeError('Invalid "options" parameter: ' + JSON.stringify(options));
^
TypeError: Invalid "options" parameter: "postgres://me:complete@localhost:5432/education_be"

我的配置文件:

require('dotenv').config();
const pgp = require('pg-promise');

// === My initial setup just using 'pg'
// const { Pool } = require('pg');
// const pool = new Pool({
//  name: process.env.name,
//  password: process.env.password,
//  host: process.env.host,
//  database: 'education_be',
//  port: process.env.port
// });

// === My first attempt following the guide would receive errors like:
// === Error: Option "user" is not recognized.
const connection = {
    name: 'me',
    password: 'password',
    host: 'localhost',
    database: 'education_be',
    port: 5432
};

// === attempting (unsuccessfully) to just use the address
const db = pgp('postgres://me:complete@localhost:5432/education_be');

module.exports = db;

【问题讨论】:

  • 您没有关注documented initialization steps,因此出现错误。
  • 你是对的!我今天早些时候抛弃了所有东西,从头开始研究你的资源,这变得很明显。

标签: javascript express pg-promise


【解决方案1】:

我迟到了,但希望这可以帮助遇到同样问题的其他人。尽管您没有选项,但您必须在 pg-promise require 语句中包含括号。

const pgp = require('pg-promise')();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-10
    • 1970-01-01
    • 2016-09-13
    • 2018-08-23
    • 2022-01-12
    • 2020-03-29
    相关资源
    最近更新 更多