pino
pino copied to clipboard
TypeScript complains with `This expression is not callable.` using basic init
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?
@kibertoad ptal
@whoyawn which pino and TypeScript versions are you using?
Here are my versions
"pino": "^8.0.0",
"typescript": "^4.6.4"
@whoyawn try this:
import { pino } from 'pino'
const logger = pino()
logger.info('hello world')
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!
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.