pino icon indicating copy to clipboard operation
pino copied to clipboard

TypeScript complains with `This expression is not callable.` using basic init

Open whoyawn opened this issue 3 years ago • 4 comments

const logger = require('pino')()

logger.info('hello world')

leads to VSCode saying

This expression is not callable.
  Type 'typeof import("/Users/name/node_modules/pino/pino")' has no call signatures.ts(2349)

My tsconfig.json:

{
  "compilerOptions": {
    "target": "es2016",     
    "moduleResolution": "node",  
    "allowJs": true,              
    "checkJs": true,          
    "strictNullChecks": true,      
  "exclude": ["node_modules", "**/node_modules/*"]
}

Do I have to install anything else to get the compiler to recognize my js file?

whoyawn avatar Jun 02 '22 05:06 whoyawn

@kibertoad ptal

mcollina avatar Jun 02 '22 08:06 mcollina

@whoyawn which pino and TypeScript versions are you using?

kibertoad avatar Jun 02 '22 08:06 kibertoad

Here are my versions

    "pino": "^8.0.0",
    "typescript": "^4.6.4"

whoyawn avatar Jun 03 '22 05:06 whoyawn

@whoyawn try this:

import { pino } from 'pino'
const logger = pino()

logger.info('hello world')

sleroq avatar Jun 13 '22 00:06 sleroq

After wasting at least a couple of hours debugging this issue, I have a friendly word of warning to anyone using the baseUrl option in their tsconfig.json.

If you have it set to your root, it'll mess with TS's ability to properly resolve node_modules unless you also use the path option to point to the pino package like so: { "baseUrl": "./", "paths": { "pino": ["./node_modules/pino"] } }

Note: This assumes that you're importing the pino package per @sleroq 's suggestion.

The TS docs do spell out how this works, but they don't do a good enough job of forewarning users about pitfalls like this. Happy coding everyone!

maxxheth avatar Dec 21 '22 16:12 maxxheth

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Jan 23 '23 00:01 github-actions[bot]