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
Cannot import TypeScript types that have been re-exported #7882
Comments
This is the result of having I upgraded one rather small app from Next 8 + |
This is a Babel bug and I can see how this is frustrating -- we'll want to figure something out for this. |
although the error isn't clear, its root cause is from exporting a named type, not really from re exporting. this occurs with ts-loader when using transpile only, rollup plugin typescript, etc. (any tool that uses the ts.transpile api). type P = {
color: 'red'|'green'
}
MyDiv = (props:P) => <div color='red'/>
export {MyDiv, P} thats not going to work, you have to remove the 'export {MyDiv, P}` and replace with inline exports export type P = {
color: 'red'|'green'
}
export MyDiv = (props:P) => <div color='red'/> also, when you create a barrel file(index.ts), do this: good
export * from './MyDiv'
bad
export {MyDiv, P} from './MyDiv' this codemod will fix most issues "trymod": "./node_modules/.bin/codemod -p babel-plugin-codemod-named-export-declarations src/client/**/*.ts" other options: i tried to do some real hackery using gulp to expose the compiled vinyl files over a socket and serve that to next (just to avoid writes to disk). it worked but couldn't get updates to trigger:\ |
Is there a link to this upstream bug? edit: found it babel/babel#8361 (comment) |
To fix it, just replace |
i put an example repo up here https://github.com/jeremy-coleman/next-tsc-proposal |
TS 3.8 might help with this isolatedModules issue. |
This is a show stopper for my Next project that uses react native web. I am using TS 3.8.3. |
@oste TypeScript added |
Does Babel TS preset support this syntax yet? |
As far as I'm aware it does (haven't tried it) |
Babel 7.9 and Prettier 2.0 support TypeScript 3.8. |
Anyone know if there are plans to upgrade Babel to at least 7.9? I searched around, but didn't see any issues or PRs. I really need it because my monorepo packages use "import type" heavily and right now I can't not import the files I need into my Next app. |
Found a solution for now. Using next-transpile-modules allows me to import from my monorepo packages. |
This can now be accomplished via See: babel/babel#11171 |
Example landing in #13746 which will close this! |
Closes [7882](#7882). Created as requested by @timneutkens I'm unsure if that's exactly what you wanted, so let me know what you want me to change and I'll do it asap.
Hey guys - heads up just tried deploying the |
Closes [7882](vercel#7882). Created as requested by @timneutkens I'm unsure if that's exactly what you wanted, so let me know what you want me to change and I'll do it asap.
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Bug report
Describe the bug
As I wrote an issue in @zeit/next-typescript some months ago, Babel does not support to import types or interfaces from re-export files such as
index.ts
.On large project, developers create index.js (or index.ts ) to encapsulate the API calls from the web app into a single folder.
@zeit/next-typescript throws warnings when importing re-exported types, but Next.js 9 (using built-in TypeScript transpile system) throws errors in that case. So we cannot develop using re-export files.
To Reproduce
Next.js throws errors like the following if the above code is contained in some pages.
Expected behavior
Do not raise any errors and warnings.
Additional context
Babel v7 supports to transpile TypeScript files but it is only to remove types from TypeScript files. At this time, the target of import from intersection (index) files will be removed.
To solve this issue at its foundation, Babel should support re-export files and we should wait to do. However I think that to filter and ignore these errors using regular expressions makes to solve.
The text was updated successfully, but these errors were encountered: