Fixing - Cannot find name '__dirname'.ts(2304)
Alexander Kim
Posted on April 30, 2022
It happens when we try to use __dirname
in a TS file.
Steps to fix this:
Installing node types: npm i -D @types/node
Applying types in to tsconfig.json:
"compilerOptions": {
"types": ["node"],
},
Then using it:
import * as path from 'path'
console.log(__dirname)
💖 💪 🙅 🚩
Alexander Kim
Posted on April 30, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
undefined Two-Factor Authentication Using Better_Auth, Next.js, Prisma, ShadCN, and Resend
November 29, 2024