Skip to content

ESM importing a CommonJS calls getters #35859

Closed
@avaly

Description

@avaly

What steps will reproduce the bug?

Install pg npm dependency

Run the following module:

import pg from 'pg';

console.log(!!pg);

How often does it reproduce? Is there a required condition?

It always reproduces. The imported module needs to be a CommonJS module with getters.

In this case pg exports a getter that lazily tries to load another npm package: https://github.com/brianc/node-postgres/blob/master/packages/pg/lib/index.js#L32-L55

What is the expected behavior?

$ node -v
v14.12.0

$ node pg.mjs 
true

What do you see instead?

$ node -v
v14.13.0

$ node pg.mjs 
Cannot find module 'pg-native'
Require stack:
- /dev/temp/node-bugs/node_modules/pg/lib/native/client.js
- /dev/temp/node-bugs/node_modules/pg/lib/native/index.js
- /dev/temp/node-bugs/node_modules/pg/lib/index.js
true

Additional information

This change was introduced in #35249

Metadata

Metadata

Assignees

No one assigned

    Labels

    esmIssues and PRs related to the ECMAScript Modules implementation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions