Skip to content

Documentation examples not running #3190

Closed as not planned
Closed as not planned
@nboisnea

Description

@nboisnea

It seems this has been asked a few times already but I cannot find a proper answer.
How are the examples from the documentation supposed to be run?

Looking at the code in the Getting started section:

import {Client} from 'pg'

const client = new Client()
await client.connect()

const res = await client.query('SELECT $1::text as message', ['Hello world!'])
console.log(res.rows[0].message) // Hello world!
await client.end()

Is it JavaScript? TypeScript? There is no indication. If I try running this script with Node I get an error saying pg is a CommonJS module:
SyntaxError: Named export 'Client' not found. The requested module 'pg' is a CommonJS module, which may not support all module.exports as named exports.

I know the answer is to use the default export, I just wonder what is the reason for not specifying it in the documentation. And if there is a way to run this code as-is, I feel like it should at least be specified in the documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions