Skip to content
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

TypeScript: "no call signatures" when using ESM #521

Closed
joshkel opened this issue Jul 22, 2024 · 0 comments · Fixed by #522
Closed

TypeScript: "no call signatures" when using ESM #521

joshkel opened this issue Jul 22, 2024 · 0 comments · Fixed by #522

Comments

@joshkel
Copy link
Contributor

joshkel commented Jul 22, 2024

When configuring a project for ESM ("type": "module" in package.json, and tsconfig.json using "moduleResolution": "node16", "module": "node16"), if I try to import PinoPretty as import PinoPretty from 'pino-pretty' and call it, I get TypeScript error:

src/node.ts:23:48 - error TS2349: This expression is not callable.
  Type 'typeof import("node_modules/pino-pretty/index")' has no call signatures.

23       PinoPretty({ colorize: true })

Found 1 error in src/node.ts:23

If I instead try a named import (import { PinoPretty } from 'pino-pretty'), then TypeScript compiles, but Node.js throws an error at runtime:

import { PinoPretty } from 'pino-pretty';
         ^^^^^^^^^^
SyntaxError: Named export 'PinoPretty' not found. The requested module 'pino-pretty' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'pino-pretty';
const { PinoPretty } = pkg;

I noticed that Are the Types Wrong is reporting a "Missing export =" error for pino-pretty. I believe that this relates to the error I'm seeing.

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.

1 participant