Im getting "__dirname is not defined" when I define "type": "module"
on package.json. I'm doing this so I can use ES6 imports. How do I get access to __dirname in this case?
Asked
Active
Viewed 2,054 times
1

Thiago
- 746
- 1
- 10
- 22
-
2Does this answer your question? [Alternative for \_\_dirname in node when using the --experimental-modules flag](https://stackoverflow.com/questions/46745014/alternative-for-dirname-in-node-when-using-the-experimental-modules-flag) – CherryDT Mar 25 '21 at 18:37
-
Check out `import.meta.url`: `import path from 'path'; const __dirname = path.dirname(new URL(import.meta.url).pathname);` – CherryDT Mar 25 '21 at 18:37