esdname
v1.0.7
Published
Simplify the process of retrieving _ dirname from ESMs
Downloads
9
Readme
esdname
Simplify the process of retrieving _ dirname from ESMs
motivation
When using "type": "module"
in the package.json file, directly using __dirname
will result in an error:
ReferenceError: __dirname is not defined in ES module scope This file is being treated as an ES module because it has a '.js' file extension and '/Users/xxx/projects/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
esdname
aims to simplify the reference to __dirname
in this scenario.
Install
npm install esdname
yarn add esdname
pnpm install esdname
bun install esdname
Usage
import {__dirname} from 'esdname'
console.log(__dirname)