Dev Squad
anliberant's profile
Anton Liberant@anliberant•Oct 20, 2024
2.5K
Post cover image

How to Fix "__dirname is Not Defined" in NodeJs

From jsdev.space•Oct 20, 2024•2m read time

Encountering the '__dirname is not defined' error in Node.js is common when using ES modules instead of CommonJS. To fix this, you can manually define '__dirname' using 'import.meta.url', switch to CommonJS by removing 'type': 'module' from package.json, or use a bundler like Webpack. These methods ensure your project runs smoothly without the '__dirname' issue.

Sort:

anliberant's user avatar
Anton Liberant
@anliberant
Joined Jun 29. 2023
2.5K

Would you recommend this post?

Copy link
WhatsApp
Facebook
X
New Squad
  • © 2026 Daily Dev Ltd.
  • Guidelines
  • Explore
  • Tags
  • Sources
  • Squads
  • Leaderboard