DEV Community

Alexander Kim
Alexander Kim

Posted on

8 3

Fixing - Cannot find name '__dirname'.ts(2304)

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"],
},
Enter fullscreen mode Exit fullscreen mode

Then using it:

import * as path from 'path'

console.log(__dirname)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more