rollup-plugin-friendly-type-imports
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

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:

// foo/definitions.ts
export interface A {}

export const B = ...
// foo/index.ts
export { A, B } from './definitions';
// 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

// 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

Readme

Keywords

none

Package Sidebar

Install

npm i rollup-plugin-friendly-type-imports

Weekly Downloads

3,004

Version

1.0.3

License

MIT

Unpacked Size

8.63 kB

Total Files

7

Last publish

Collaborators

  • fwouts