plugins: Error: [type] is not exported by [file]

(This issue was transferred from rollup-plugin-typescript and had no issue template)

This code:

import { Type1, Type2 } from './file.ts';

export {
	Type2
}

export const fn1: Type1 = () => {
	// ...
}

Throws this error in the console:

[!] Error: 'Type2' is not exported by src/file.ts

Is there any workaround or fix for this?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 29 (7 by maintainers)

Commits related to this issue

Most upvoted comments

For desperate googlers: I’m a total rollup/typescript noob but I fixed it for myself with

https://www.typescriptlang.org/docs/handbook/modules.html#importing-types

Can we reopen? I’m still receiving this error when using Babel to compile TypeScript and importing types from third-party libs in node_modules when those types are exported in the library code using the same pattern that @Vehmloewff described above. (Example: import { GraphQLSchema } from 'graphql'.)

@thorsent the suggestion to import type { Blah } from "blah" worked perfectly with a Vite build (which uses rollup). Thanks!

In my case I was importing an enum so import type was preventing it from being used as a value. Specifying that the module that I’m importing from should remain external to the bundle in vite.config.js resolved the issue:

// ...

export default defineConfig({
  build: {
    rollupOptions: {
      external: ['@project/library'],
    },
  },
  // ...
})

@thorsent the suggestion to import type { Blah } from "blah" worked perfectly with a Vite build (which uses rollup). Thanks!

In my case I was importing an enum so import type was preventing it from being used as a value. Specifying that the module that I’m importing from should remain external to the bundle in vite.config.js resolved the issue:

// ...

export default defineConfig({
  build: {
    rollupOptions: {
      external: ['@project/library'],
    },
  },
  // ...
})

this worked for me!

I’ll try to get this working with our larger TS plugin updates.

I ran into this issue when trying to use an enum that was exported by the library’s typedef but which wasn’t exported in the library’s es6 module. There was no help from the compiler until switching from import { Blah } from "blah" to import type { Blah } from "blah". Then the compiler barfed up the problem. I worked around the problem by just using the raw string, but there might be a magic sequence of tsconfig that would have helped.

Having same issue when I build in Vite. All my interfaces get the import/export error

This is fixed with @rollup/plugin-typescript version 3.0.0!

Well. You are referring to a issue in old repository and it was closed due to repository move. However this is not resolved right now. For me the workaround is not acceptable because I have a very large code base. The rollup-plugin-typescript2 handles this situation very well but it is really slow after upgrading to typescript 3.4.

For desperate googlers: I’m a total rollup/typescript noob but I fixed it for myself with

https://www.typescriptlang.org/docs/handbook/modules.html#importing-types

This worked for me too (import type) but it does seem like a workaround.

There is a workaround for this, I’ll be it is not an ideal one, but it is what I have been using in the meantime.

Instead of

import { Type1, Type2 } from './file.ts';

export {
	Type2
}

export const fn1: Type1 = () => {
	// ...
}

I just

import { Type1, Type2 } from './file';

export const fn1: Type1 = () => {
	// ...
}

export * from './file';

The only problem with this is that I do not really want to export Type1. But in my case, I would rather have extra export that not have the ones I need.

Thanks for responding!

I think that this issue is still relevant @shellscape. I would be glad to know that it will be transferred to the new repo.