You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tries to compile sources that are not supposed to be loaded #267
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 /client directory (by ts-loader), and I have ts file say server-somthing.ts in /server (that is loaded using ts-node) - this file is not shared with client part.
And say there is a mistake in server-somthing.ts.
But when webpack lanunches it error with compile error in server-somthing.ts. To get rid of it I have to limit files in tsconfig and if I use awesome-typescript-loader instead of ts-loader (just replace for it in webpack.confg) it works ok - doesn't try to compile server-somthing.ts.
Reacted by Evgeniy Zhukovskiy, Evgeniy Timokhov, Ben Southgate, Vien Luong, Robert Grosse, Eric Noguchi and Ilan Schemoul
Same things for me:
ts-loader is giving error from file not used in the entry, but are part of the file tree.
I have 5 different ts entry path in the same filetree, and it looks like they are parsing each-other's files... Wonder if it doesnt overslow the build speed... @_@
Reacted by Evgeniy Zhukovskiy, Evgeniy Timokhov and Girla
@blakeembrey Hi, guys! This issue prevents us from using ts-loader. We've made a simple example so you can reproduce it.
This example contains tests folder with additional dependencies in package.json which are not to be installed to build the base project.
just unpack it, and run
npm install
./node_modules/.bin/webpack
You'll get an error in tests/src/test.ts which is not required to build the base project: (1,25): error TS2307: Cannot find module 'jquery'.
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?
On after-compile it checks list [1] for errors and gathers all the files in the project like ts-loader, but then it checks where the compiled files list [2] contains them or not. If a file is not in the list it puts it in phantomImports:
@johnnyreilly first we need to be sure there no need for files and include parts from tsconfig.json. Is there any counter-example? And also it will break compatibility.
@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 files and include are both optional.
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! 😄
start implementing [...] use that as a basis for conversation
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:
files and include from tsconfig.json => tsc
webpack entry (and nothing else except compilerOptions) => ts-loader (the way rollup-plugin-typescript2 works)
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.
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 onlyCompileBundledFiles like so
I still find it astonishing that ts-loader is broken by default, but at least there's a workaround.
Reacted by Tanguy Krotoff, Eric Noguchi, Eugeny Voronin, Phú, Sergio Mazzoleni, Kaelan Cooter, Rıdvan Özaydın, Nico Castro, Raphael Luba and Stanislav Gromov
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 onlyCompileBundledFiles is one of a number of flags that allows you to deviate behaviour from tsc and align closer with typical webpack behaviour.
ts-loader is broken by default
It's not, it's just not the behaviour you expected.
I am still seeing this issue in ts-loader 3.2.0. It makes ts-loader and webpack literally unusable for us.
To be clear: is it usable with the onlyCompileBundledFiles flag? Or not?
I was under the impression that ts-loader is intended to be used with webpack. Why not follow the standard webpack behavior in that case?
To be clear: is it usable with the onlyCompileBundledFiles flag? Or not?
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.
I was under the impression that ts-loader is intended to be used with webpack. Why not follow the standard webpack behavior in that case?
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 onlyCompileBundledFiles gives you what you need. That's fantastic!
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 : 🌻
Yes this issue caught me off guard as well
And for the record awesome-typescript-loader is also doing the same thing but each have a different workaround
onlyCompileBundledFiles fixes the issue to ts-loader
on the other hand fixing the issue for awesome-typescript-loader seems to be adding a "files": [],in tsconfig.json but ts-loader and TSC complains that TS18002: The 'files' list in config file 'tsconfig.json' is empty.
Activity
blakeembrey commentedon Aug 20, 2016
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.
wclr commentedon Aug 21, 2016
I serve files mostly in
/clientdirectory (byts-loader), and I have ts file sayserver-somthing.tsin/server(that is loaded usingts-node) - this file is not shared with client part.And say there is a mistake in
server-somthing.ts.But when webpack lanunches it error with compile error in
server-somthing.ts. To get rid of it I have to limit files intsconfigand if I use awesome-typescript-loader instead ofts-loader(just replace for it in webpack.confg) it works ok - doesn't try to compileserver-somthing.ts.Vloz commentedon Sep 17, 2016
Same things for me:
ts-loader is giving error from file not used in the entry, but are part of the file tree.
I have 5 different ts entry path in the same filetree, and it looks like they are parsing each-other's files... Wonder if it doesnt overslow the build speed... @_@
timocov commentedon Oct 12, 2016
@blakeembrey Hi, guys! This issue prevents us from using ts-loader. We've made a simple example so you can reproduce it.
This example contains tests folder with additional dependencies in package.json which are not to be installed to build the base project.
just unpack it, and run
You'll get an error in
tests/src/test.tswhich is not required to build the base project:(1,25): error TS2307: Cannot find module 'jquery'.Example project: ts-loader-fail.zip
johnnyreilly commentedon Oct 12, 2016
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 🌷
ezhukovskiy commentedon Oct 12, 2016
@johnnyreilly Hi, this issue is solved in awesome-typescript-loader.
The problem is that
after-compilein ts-loader looks for errors in all files from tsconfig.json.Look at how it is done in
awesome-typescript-loader:https://github.com/s-panferov/awesome-typescript-loader/blob/master/src/instance.ts#L396
It seems that they gather all files the loader was called for and checks them in
after-compile.I believe that you will be able to understand more from their code knowing how it is done in ts-loader.
johnnyreilly commentedon Oct 16, 2016
Thanks for the clarification @eugenezee - very helpful. PRs welcome!
johnnyreilly commentedon Oct 17, 2016
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...
ezhukovskiy commentedon Oct 20, 2016
@johnnyreilly Hi,
As soon as I understand it stores files when it is called to compile it:
https://github.com/s-panferov/awesome-typescript-loader/blob/master/src/index.ts#L61
phantomImports:https://github.com/s-panferov/awesome-typescript-loader/blob/master/src/index.ts#L58
On
after-compileit checks list [1] for errors and gathers all the files in the project like ts-loader, but then it checks where the compiled files list [2] contains them or not. If a file is not in the list it puts it inphantomImports:https://github.com/s-panferov/awesome-typescript-loader/blob/master/src/instance.ts#L443
He uses
phantomImportsto find appropriate declaration (d.ts) files. He puts them incompilation.assetsandcompilation.fileDependencies.johnnyreilly commentedon Oct 25, 2016
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!
johnnyreilly commentedon Oct 26, 2016
Related to #54
Make both app and tests compile now. For tests, Node 6.9 needed
wclr commentedon Nov 28, 2016
Are there recommendation how it could be worked around?
ezhukovskiy commentedon Nov 29, 2016
@whitecolor we ought to use awesome-webpack-loader for tests sub-project and ts-loader for the base project, which is inconvenient
14 remaining items
tkrotoff commentedon Sep 28, 2017
What about ignoring the
filesandincludeparts oftsconfig.jsonand only compile the files known to webpack? This would simplify everything.This is what rollup-plugin-typescript2 does, it only checks for the
compilerOptionspart oftsconfig.json(see #646).johnnyreilly commentedon Sep 28, 2017
We'd be open to a pull request if you fancied implementing this @tkrotoff.
tkrotoff commentedon Sep 28, 2017
@johnnyreilly first we need to be sure there no need for
filesandincludeparts fromtsconfig.json. Is there any counter-example? And also it will break compatibility.johnnyreilly commentedon Sep 28, 2017
@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
filesandincludeare both optional.tkrotoff commentedon Sep 28, 2017
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.
johnnyreilly commentedon Sep 29, 2017
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! 😄
tkrotoff commentedon Sep 30, 2017
@johnnyreilly
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?
johnnyreilly commentedon Sep 30, 2017
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.
johnnyreilly commentedon Oct 26, 2017
This should be resolved by @maier49's PR: #671
Hope to ship this with ts-loader 3.1.0
Storyyeller commentedon Dec 20, 2017
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
onlyCompileBundledFileslike souse: [{loader: 'ts-loader', options: {onlyCompileBundledFiles: true}}]I still find it astonishing that ts-loader is broken by default, but at least there's a workaround.
johnnyreilly commentedon Dec 21, 2017
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
onlyCompileBundledFilesis one of a number of flags that allows you to deviate behaviour from tsc and align closer with typical webpack behaviour.It's not, it's just not the behaviour you expected.
To be clear: is it usable with the
onlyCompileBundledFilesflag? Or not?Storyyeller commentedon Dec 21, 2017
I was under the impression that
ts-loaderis intended to be used with webpack. Why not follow the standard webpack behavior in that case?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.
johnnyreilly commentedon Dec 21, 2017
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
onlyCompileBundledFilesgives you what you need. That's fantastic!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 : 🌻
ericnoguchi commentedon Dec 31, 2017
Hello,
Yes this issue caught me off guard as well
And for the record awesome-typescript-loader is also doing the same thing but each have a different workaround