-
Notifications
You must be signed in to change notification settings - Fork 361
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
Breaks when trying to import typescript outside of directory #808
Comments
I wonder if you could find a remedy to this? I have the same issue. I'm trying to include some external packages in the bundle because I'm in a monorepo and get the exact same error. |
I am also experiencing this |
Just to check as no one's provided a reproduction, are people seeing this when importing types/interfaces or only when importing things that would be transpiled to JS? I cannot reproduce the former, but can the latter. Edit: Seems like it might be an upstream issue with rpt2, see ezolenko/rollup-plugin-typescript2#216. It seems like exporting types/interfaces from other directories is fine, but not anything else. |
My experience has been anything that is Typescript breaks it (including types/interfaces) while regular JS works fine. |
That relates to what I am doing. When I tried importing typescript files from outside the parent directory I got that error. I had to move the files inside the project root directory to import them successfully. I will try to provide a repro as soon as possible |
Interesting, might be an issue if the TS file imports items itself? Can definitely import pure types/interfaces from an external (to the project) module without issue, though, worth noting that I don't believe these types end up being built into your build output, so more of a "doesn't impede the build" sort of thing than "works". Regardless a repro would help at least to help narrow down these issues/behaviors. I don't think there's much we can do, but knowing the limits would be better. |
Here I am again facing this exact problem, sorry too busy to make that repro |
I will give more context I hate having to transpile my typescript files for every library I make up, I would have to maintain a dozen of libraries and transpile them to CJS and ESM and that gets annoying. So I just said fuck it and instead of writing libraries I write typescript code under workspace/modules. Bear with me, I will explain what I mean. I work with the following structure
Well then, inside my-cool-project I use microbundle to bundle all that code into a single bundle.js file Unfortunately, I am running into this issue where what seems to be a bug is causing microbundle to treat my typescript code that is external to the project as Flow code instead of typescript code, throwing syntax errors like the one OP mentioned |
Well, as I've said, you should be able to import external types (at least I can in all of my tests), but this issue is upstream. Not much we can do about it. |
Good morning (for me), I've made a repro for this. https://github.com/icaro-capobianco/bundle-bug-repro I will also be investigating the cause |
@rschristian |
That's something that Babel handles. Parsing is its job. Regardless, TS is handled by rpt2. We don't use Babel to transpile AFAIK. |
So @icaro-capobianco created ezolenko/rollup-plugin-typescript2#295 referencing this downstream issue and I recently investigated and fixed Ícaro's repro in a fork. I did a root cause analysis in ezolenko/rollup-plugin-typescript2#295 (comment) and it turns out this was due to I submitted a PR in #967 to update rpt2 to the latest release v0.32.0, which fixes two different issues with monorepos (this and symlinks).
Not to transpile TS, but it runs after rpt2 in the plugin chain in order to support Babel plugins and |
Maybe mixing up my issues here, but I thought this failed even with types-only files, that would never be part of the graph as they contain no JS. Fair enough though.
Ah, interesting. Good to know. |
You'd be referring to the long-standing ezolenko/rollup-plugin-typescript2#7 and its various related issues, such as ezolenko/rollup-plugin-typescript2#211 and ezolenko/rollup-plugin-typescript2#298 where I began a root cause analysis and actually have more or less figured out how to solve this (will do a RCA write-up and maybe draft PR soon, but it requires a heck of a lot of testing, so think I'll need to build out an integration test suite prior to release). But that has nothing to do with
Actually I was wrong on this one, the stacktrace shows it comes from |
It was this issue, just my memory of the issue was backwards it looks like: #808 (comment) Type-only imports were a-ok. |
Ah I see. In the specific case of this issue, type-only imports probably didn't cause problems because they don't currently run through the Basically, importing a type-only file outside of the project dir wouldn't encounter this issue bc rpt2 doesn't transform/report diagnostics for such files anyway due to ezolenko/rollup-plugin-typescript2#211. In other words, one issue masked another issue 😅 Brief summary of my WIP RCA for the type-only issue for those interestedI believe it occurs because the compiled JS doesn't contain imports to the type-only files. So, when Rollup parses that compiled code, it never calls the Can stay tuned into that issue for more details over time. EDIT: see full RCA in ezolenko/rollup-plugin-typescript2#298 (comment) |
I'm working in a typescript monorepo structured sort of like this
I'm getting weird errors whenever in my
package
code I try to import a typescript module from outside thepackage
directory. It's like microbundle doesn't know that it's a typescript file.For example, I
import
some typescript types that are generated by graphql-code-generator and live in the top levelshared
directory. When I import the file and run my build script I get this error message:It looks like microbundle doesn't know this is typescript and thinks it's flow...
However, when I copy the contents of that file into the
package
directory andimport
that instead, it builds just fine. Same with a symlink to that file from within the package.Just to be certain, I explicitly added the relative path to the
include
array in thepackages/tsconfig.json
, and got the same error.Why is microbundle unable to understand
import
s of files outside of thepackage
directory? Or am I missing some configuration or something like that?The text was updated successfully, but these errors were encountered: