Skip to content

Types issue with ESM setup #2120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
iamchathu opened this issue Jan 23, 2025 · 6 comments · May be fixed by #2223
Open

Types issue with ESM setup #2120

iamchathu opened this issue Jan 23, 2025 · 6 comments · May be fixed by #2223

Comments

@iamchathu
Copy link

The types seems broken in ESM Typescript setup with module resolution set to "node16".

Pino is commonjs and normally should work with the project without issues.

Here is the reproduction minimal setup.

https://stackblitz.com/edit/stackblitz-starters-kuphd3r7?file=tsconfig.json,src%2Findex.ts

@mcollina
Copy link
Member

I think this would do the trick:

import pino from 'pino';

const logger = pino({});

@iamchathu
Copy link
Author

Still the error is the same

Type 'typeof import("/home/projects/stackblitz-starters-kuphd3r7/node_modules/pino/pino")' has no call signatures.

3 const logger = pino({});
                 ~~~~


Found 1 error in src/index.ts:3

@colinmollenhour
Copy link

So is this currently the only/correct way to use it without throwing TS errors?

import pino from 'pino';

const logger = pino.default({});

@Tobbe
Copy link

Tobbe commented Apr 26, 2025

I'm building for both CJS and ESM, so I had to do const logger = (pino.default || pino)({}); to both please TS and to make both the outputs work.

@cluah
Copy link

cluah commented May 10, 2025

you can also manually import { pino } from 'pino'

but more people will end up here as that's not the default VSCode auto-import behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants