esdname
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

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)

Readme

Keywords

none

Package Sidebar

Install

npm i esdname

Weekly Downloads

0

Version

1.0.7

License

ISC

Unpacked Size

3.58 kB

Total Files

5

Last publish

Collaborators

  • fuzhiqiang