Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: [type] is not exported by [file] #71

Closed
Vehmloewff opened this issue Nov 15, 2019 · 29 comments
Closed

Error: [type] is not exported by [file] #71

Vehmloewff opened this issue Nov 15, 2019 · 29 comments

Comments

@Vehmloewff
Copy link

Vehmloewff commented Nov 15, 2019

(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?

@shellscape
Copy link
Collaborator

Hey folks (this is a canned reply, but we mean it!). Thanks to everyone who participated in this issue. We're getting ready to move this plugin to a new home at https://github.com/rollup/plugins, and we have to do some spring cleaning of the issues to make that happen. We're going to close this one, but it doesn't mean that it's not still valid. We've got some time yet before the move while we resolve pending Pull Requests, so if this issue is still relevant, please @ me and I'll make sure it gets transferred to the new repo. 🍺

@Vehmloewff
Copy link
Author

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.

@shellscape shellscape transferred this issue from rollup/rollup-plugin-typescript Dec 3, 2019
@shellscape shellscape reopened this Dec 3, 2019
@ziofat
Copy link
Contributor

ziofat commented Dec 9, 2019

Hi, is this fixed or not?

@NotWoods
Copy link
Member

NotWoods commented Dec 9, 2019

It's not fixed yet, it's just been transferred to the new repository.

@Vehmloewff
Copy link
Author

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.

@Vehmloewff
Copy link
Author

I just realized that this is a duplicate of rollup/rollup-plugin-typescript#28. Sorry for the inconvenience.

@ziofat
Copy link
Contributor

ziofat commented Dec 25, 2019

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.

@shellscape
Copy link
Collaborator

@ziofat if you'd like to put together a minimal reproduction in a repo that we can clone, I'd be happy to reopen this. We're going to need a reproduction to triage this.

@ziofat
Copy link
Contributor

ziofat commented Dec 25, 2019

@shellscape OK, I will try to make a reproduction later.

@petejodo
Copy link

I created a repo that reproduces the issue here https://github.com/PeteJodo/repro-rollup-typescript-export-type-issue

I get this output

> [email protected] rollup /Users/pjodogne/Projects/TEMP/repro-rollup-typescript-export-type-issue
> rollup -c


src/index.ts → dist/index.js...
[!] Error: 'IExample' is not exported by src/dep.ts
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
src/index.ts (1:9)
1: export { IExample, MyExample } from './dep';
            ^
Error: 'IExample' is not exported by src/dep.ts
    at error (/Users/pjodogne/Projects/TEMP/repro-rollup-typescript-export-type-issue/node_modules/rollup/dist/rollup.js:5365:30)
    at Module.error (/Users/pjodogne/Projects/TEMP/repro-rollup-typescript-export-type-issue/node_modules/rollup/dist/rollup.js:9708:9)
    at handleMissingExport (/Users/pjodogne/Projects/TEMP/repro-rollup-typescript-export-type-issue/node_modules/rollup/dist/rollup.js:9625:21)
    at Module.getVariableForExportName (/Users/pjodogne/Projects/TEMP/repro-rollup-typescript-export-type-issue/node_modules/rollup/dist/rollup.js:9829:17)
    at Module.includeAllExports (/Users/pjodogne/Projects/TEMP/repro-rollup-typescript-export-type-issue/node_modules/rollup/dist/rollup.js:9876:35)
    at Promise.all.then (/Users/pjodogne/Projects/TEMP/repro-rollup-typescript-export-type-issue/node_modules/rollup/dist/rollup.js:13083:24)
    at <anonymous>

@weyert
Copy link

weyert commented Dec 30, 2019

Yes, I have the same issue and temporary not exporting the props of my React components due to this issue. I have also tried rollup-plugin-typescript2 but that's not working at all, keep getting failed to transpile '/Users/work/experiment/src/index.ts' and have no idea what that is supposed to mean.

@shellscape
Copy link
Collaborator

@NotWoods this might be up your alley. @petejodo put together a reproduction repo for reference, and it might be related to the updates you have planned already.

@shellscape shellscape reopened this Dec 30, 2019
@NotWoods NotWoods self-assigned this Dec 31, 2019
@NotWoods
Copy link
Member

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

@NotWoods
Copy link
Member

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

@hasangenc0
Copy link
Contributor

@rollup/plugin-typescript
Hi, congrats to fix this bug 🎉.
When the new version will be released?

@ersinakinci
Copy link

ersinakinci commented Apr 15, 2020

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'.)

@shellscape
Copy link
Collaborator

@earksiinni you're welcome to open a new issue with a proper reproduction. We won't be reopening this one.

tjmw added a commit to guardian/braze-components that referenced this issue Aug 25, 2020
Exporting the type explicitly did not work for me (I was getting errors
that ExampleComponent did not export a Prop type, even when it did). The
workaround specified here worked for me:
rollup/plugins#71 (comment)
@marcus13371337
Copy link

Solved this issue by doing the following:
index.ts

import { TypeYouWantToExport as TypeYouWantToExportReal } from './file1'

export type TypeYouWantToExport = TypeYouWantToExportReal

@kswope
Copy link

kswope commented Jan 5, 2021

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

@chrisrrowland
Copy link

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.

@dayrlism10
Copy link

this resolved my concern, hope it helps

export type MyType = import("./types.ts").MyType;

@spadgeaki
Copy link

Hi, i had similar issue but with react-beautiful-dnd. It helped to yarn install -D @types/react-beautiful-dnd

@matthew-dean
Copy link

matthew-dean commented Nov 3, 2021

This also fails with @rollup/plugin-sucrase FYI. Can however this was solved with the typescript plugin be applied to Sucrase?

@mklueh
Copy link

mklueh commented Jun 26, 2022

Running into this with Nuxt 3.0.0-rc.4 when trying to import from a library, while it was previously working

@thorsent
Copy link

thorsent commented Aug 1, 2023

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.

@mw-sezzle
Copy link

mw-sezzle commented Oct 11, 2023

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

@boshoff
Copy link

boshoff commented Nov 16, 2023

@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'],
    },
  },
  // ...
})

@codeho
Copy link

codeho commented Nov 30, 2023

@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!

@D-Thrane
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests