# babel-plugin-transform-import-meta

> Transforms import.meta for nodejs environments

Latest version **3.1.0** (published 2026-10-15) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-transform-import-meta
pnpm add babel-plugin-transform-import-meta
yarn add babel-plugin-transform-import-meta
bun add babel-plugin-transform-import-meta
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2026-10-15 |
| First published | 2019-07-27 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 24.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 51 |
| Author | Javier Garcia |
| Maintainers | javiertury |
| Keywords | babel-plugin, import-meta |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-transform-import-meta
- Repository: https://github.com/javiertury/babel-plugin-transform-import-meta
- Homepage: https://github.com/javiertury/babel-plugin-transform-import-meta#readme
- Issues: https://github.com/javiertury/babel-plugin-transform-import-meta/issues
- npm.io page: https://npm.io/package/babel-plugin-transform-import-meta

## Dependencies (2)

- [tslib](https://npm.io/package/tslib.md) ^2.8.1
- [@babel/template](https://npm.io/package/@babel/template.md) ^8.0.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 3.1.0 (latest) — 2026-10-15
- 2.2.0-alpha.1 (alpha) — 2022-06-21
- 3.0.0 — 2026-06-28
- 2.3.3 — 2025-06-03
- 2.3.2 — 2025-01-03
- 2.2.1 — 2023-08-04
- 2.2.0 — 2022-06-21
- 2.1.1 — 2022-02-03
- 2.1.0 — 2021-09-10
- 2.0.0 — 2021-04-21
- 1.0.1 — 2019-12-20
- 1.0.0 — 2019-07-27

## README

# babel-plugin-transform-import-meta

Transforms `import.meta` for nodejs environments. This plugin supports transforming the following apis:

- `import.meta.dirname`
- `import.meta.filename`
- `import.meta.resolve(specifier)`
- `import.meta.url`

## `import.meta.dirname`

```js
console.log(import.meta.dirname);
```

Is replaced with

```js
console.log(__dirname);
```

## `import.meta.filename`

```js
console.log(import.meta.filename);
```

Is replaced with

```js
console.log(__filename);
```

## `import.meta.resolve(specifier)`

```js
console.log(import.meta.resolve(myCustomFunction('path', 'file')));
```

Is replaced with

```js
console.log(require('url').pathToFileURL(require.resolve(myCustomFunction('path', 'file'))).toString());
```

## `import.meta.url`

```js
console.log(import.meta.url);
```

Is replaced with

```js
console.log(require('url').pathToFileURL(__filename).toString());
```

## Installation

Install this package

```sh
npm install --save-dev babel-plugin-transform-import-meta
```

and add it to your babel plugins in `babel.config.json`

```json
{
  "plugins": [
    "babel-plugin-transform-import-meta"
  ]
}
```

## Settings

### ES6 modules

It's possible to use ES6 modules for the output. Useful to delegate module transformation to other plugins.

```json
{
  "plugins": [
    ["babel-plugin-transform-import-meta", { "module": "ES6" }]
  ]
}
```

## Credits

Based on a previous project "babel-plugin-import-meta" by The Polymer Authors

---
_Source: https://npm.io/package/babel-plugin-transform-import-meta · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
