# rollup-plugin-friendly-type-imports

> This plugin is primarily intended for Vite users who want to use TypeScript without being forced to set `isolatedModules: true` in their `tsconfig.json`.

Latest version **1.0.3** (published 2022-04-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install rollup-plugin-friendly-type-imports
pnpm add rollup-plugin-friendly-type-imports
yarn add rollup-plugin-friendly-type-imports
bun add rollup-plugin-friendly-type-imports
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2022-04-08 |
| First published | 2021-07-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 8.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Maintainers | fwouts |

## Links

- npm: https://www.npmjs.com/package/rollup-plugin-friendly-type-imports
- Repository: https://github.com/fwouts/rollup-plugin-friendly-type-imports
- npm.io page: https://npm.io/package/rollup-plugin-friendly-type-imports

## Dependencies (1)

- [typescript](https://npm.io/package/typescript.md) ^4.5.5

## Recent versions

- 1.0.3 (latest) — 2022-04-08
- 1.0.2 — 2022-02-10
- 1.0.1 — 2021-07-17
- 1.0.0 — 2021-07-17
- 0.0.4 — 2021-07-11
- 0.0.3 — 2021-07-11
- 0.0.2 — 2021-07-11
- 0.0.1 — 2021-07-11

## README

# rollup-plugin-friendly-type-imports

This plugin is primarily intended for Vite users who want to use TypeScript without being forced to set `isolatedModules: true` in their `tsconfig.json`.

It's also a valid Rollup plugin, and as such may be used in other, similar situations.

## What problem does this solve?

If you try to use Vite in a TypeScript codebase, you may run into issues if your code contains imports of re-exported types.

Imagine for example:
```ts
// foo/definitions.ts
export interface A {}

export const B = ...
```

```ts
// foo/index.ts
export { A, B } from './definitions';
```

```ts
// bar/usage.ts
import { A, B } from 'foo/definitions';
```

If you use Vite, this will fail because, once transpiled to JavaScript, `foo/index.js` tries to re-export an entity `A` from `foo/definitions.js`, but that value doesn't exist.

The browser will crash with:
```
Uncaught SyntaxError: The requested module '/foo/definitions.ts' does not provide an export named 'A'
```

## Solution

The solution is to generate a fake `A` entity, which is in fact the value `null`, so the browser will no longer complain. This is exactly what `rollup-plugin-friendly-type-imports` does.

## Usage

```js
// vite.config.js
import friendlyTypeImports from 'rollup-plugin-friendly-type-imports';

export default {
  plugins: [
    friendlyTypeImports()
  ],
};
```

## Performance

You should avoid using this plugin if you can.

Each TypeScript file needs to go through another round of parsing. This happens in JavaScript, so it can be significantly slower than the "pure" solution which only relies on esbuild.

## License

MIT

---
_Source: https://npm.io/package/rollup-plugin-friendly-type-imports · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
