-
-
Notifications
You must be signed in to change notification settings - Fork 431
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
Tries to compile sources that are not supposed to be loaded #267
Comments
Can you give more information? I can't tell you without seeing an example, but most like it's not compiling it - it's using it for type information and that would be expected. |
I serve files mostly in And say there is a mistake in But when webpack lanunches it error with compile error in |
Same things for me: |
@blakeembrey Hi, guys! This issue prevents us from using ts-loader. We've made a simple example so you can reproduce it.
You'll get an error in Example project: ts-loader-fail.zip |
Hi @timocov, Thanks for the repro - that's very helpful and we're always grateful when someone can provide a clear example of something not working as they expect. We're open to a receiving a PR that will resolve this 🌷 |
@johnnyreilly Hi, this issue is solved in awesome-typescript-loader. |
Thanks for the clarification @eugenezee - very helpful. PRs welcome! |
Hi @EugeneZee, I took a quick look at the awesome-typescript-loader approach and it wasn't obvious to me where they gather just the files the loader was called for. Could you clarify that for me please? I'm interested in using this approach; I just need to understand exactly how it works... This looks like it might be what you're talking about? https://github.com/s-panferov/awesome-typescript-loader/blob/master/src/instance.ts#L443 But without diving deep into the source of atl it's not clear to me where the information about which files the loader was called for comes from... |
@johnnyreilly Hi,
On https://github.com/s-panferov/awesome-typescript-loader/blob/master/src/instance.ts#L443 He uses |
Thanks for the write up @EugeneZee - very helpful. This is on my radar but I'm not sure when I'll get to it; in the meantime PRs are always welcome! |
Related to #54 |
Due to a bug in ts-loader (TypeStrong/ts-loader#267) tests will always be compiled even from webpack. So I've moved them for now to a separate folder. TODO: need to re-check why type declarations from npm (@types) does not work.
Are there recommendation how it could be worked around? |
@whitecolor we ought to use awesome-webpack-loader for tests sub-project and ts-loader for the base project, which is inconvenient |
The best workaround is a pull request 😄 More seriously this isn't an issue I've encountered in the various projects I've worked on. If it helps I tend to avoid having code that would "collide" |
I think that it's OK in some cases. We should expect |
I'm OK with new behavior as an option "bundle", but it is critical to have this option at least to keep tests in the project repository which is a common approach. |
This is an example of a toy project of my own which does exactly that but doesn't appear to suffer from this issue: https://github.com/johnnyreilly/proverb-signalr-react?files=1 |
@johnnyreilly that's because you have all dependencies in root |
This is not to belittle the issue you are facing - rather to provide an example of an approach which seems to work (at least for some use cases) |
That's certainly true but they won't be included when I bundle for release. As such I'm OK with that (whilst remaining open to better solutions should they present themselves) |
I think the problem is about a lot of time which spend on download unnecessary deps, not about what will be in result bundle. There is workaround, but only for typescript 2.1 - inherited projects. |
What do you mean by |
You can make base project file which includes compiler options and some other settings ( |
Possible it helps you exclude tests files (which placed nearly with source files) too (by using specific |
I find that using this loader also tries to compile files that are in the tsconfig exclude option: https://github.com/quantumjs/solar-popup/blob/master/tsconfig.json#L8 |
I also just walked into this issue, where one project with failing types is now causing the other 3 projects in the same repository to also show errors when compiling. Yes, this is the same behaviour as running |
Possibly related to |
What about ignoring the This is what rollup-plugin-typescript2 does, it only checks for the |
We'd be open to a pull request if you fancied implementing this @tkrotoff. |
@johnnyreilly first we need to be sure there no need for |
@tkrotoff - if it goes in it would be behind a flag. ts-loader aims to be a drop in replacement for tsc as much as is practical. Since this would deviate from that I'd want this to be "opt-in" behaviour; not default. To your question: I believe |
There is a misunderstanding. Of course files and include are optional in tsconfig, not talking about that. What I suggest is to totally ignore them inside ts-loader: ts-loader would only compile what webpack provides, nothing more. |
Ok I see. As long as you're ok with this being opt-in rather than default behaviour then I say start implementing in a PR and use that as a basis for conversation. Don't worry about failing tests or anything- just hack about, raise a PR and talk to me. Let's see what happens! 😄 |
I prefer you to be sure that the idea is good and it's the proper way to handle things. I don't want to spend hours on a PR that ends up with "sorry, the idea is wrong, here is a valid use case where we need files/include from tsconfig.json". For me it's clear:
In my opinion it should have been this way from the start. Currently ts-loader mix tsconfig.json files/include and webpack entries (+ other things hence the current issue) and it's a mess. Ping @s-panferov any opinion on this? |
On the face of it seems reasonable. I'd suggest start attempting it - it might be the case that doing so reveals "dragons". Or not. Purely from my own perspective I find it easier to think about code during implementation; hence my suggestion. As always, @s-panferov views could be helpful. Just to be clear though, I would plan to put this behaviour behind a feature flag (loader option) at least initially. If it's clear that this can be inferred from the tsconfig.json then great. But I'm not counting on it. |
I am still seeing this issue in ts-loader 3.2.0. It makes ts-loader and webpack literally unusable for us. Webpack loaders are supposed to be called to handle the files you're building with webpack - not to spend minutes blindly processing every file in your repository and then blowing up because of unrelated issues. Edit: For anyone else reading, you can work around this bug by specifying the option
I still find it astonishing that ts-loader is broken by default, but at least there's a workaround. |
ts-loader intentionally mirrors the behaviour of tsc as closely as possible. If tsc thinks your code is probably broken then ts-loader should say so too. We do this so there's not a disconnect between the editor / IDE experience and your build. The
It's not, it's just not the behaviour you expected.
To be clear: is it usable with the |
I was under the impression that
Yes. The issue is that there were a large number of other files in the repository which shouldn't be checked but which ts-loader checks by default. Setting the flag fixed this. P.S. Sorry for the overly harsh language earlier. I understand that it is working as intended, I just can't understand why it is intended to behave like that, and I don't think the default behavior makes sense, which makes it a bug from my perspective. |
It is intended to be used with webpack. However we want the typical compiler behaviour to tie up with ts-loader as much as possible. Partly to give a good editor / IDE experience. Partly because webpack is not the only game in town. People may move to webpack and away from webpack as a build choice. There can be good reasons to do either. Ideally that should be a frictionless experience. We don't want people to have to use webpack / ts-loader - it should be a choice. The minute we have default behaviour that deviates from tsc then we've started down that unfortunate road. It might not be the choice you prefer but it's not something that's likely to change, for the reasons given. That said, I'm glad It's possible (probable!) that our docs could be clearer around this. If you wanted to submit a docs PR to improve things I'd happily take a look. All the best : 🌻 |
Hello, Yes this issue caught me off guard as well
|
Webpack 2 and TS2 beta
ts-loader tries to compile even source that should not be loaded by webpack. Is it expected behaviour?
The text was updated successfully, but these errors were encountered: