-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Discovering .ts files under node_modules resulting in them being compiled #6964
Comments
I've added a potential fix for this into #6928, as both depend on knowing if code was discovered downstream of a search under |
I think this is a kinda serious issue in node based development. Currently I see the following options when using
Or leave I know, there will be much rejoicing when global includes arrive #1927 -- but what until then??
|
I'm also facing this issue. My use case is the following:
When compiling projectB, without the --outFile flag all works exactly as it should, unfortunately when using --outDir in conjunction with --module it bundles more than it should, bringing the code from projectA over to the bundle of projectB. Not what we were looking for. Anyone knows a workaround for this? |
in projectA's package.json, define `"typings": "<main .d.ts file of projectA>"``. this will force the compiler to load the .d.ts instead of loading the .ts files. |
Thanks @mhegazy! Although in this case we don't have a import "projectA/components/grid";
import "projectA/components/combobox";
... And I rather not maintain a separate file that exports all of the components. We want to avoid giving the developers the possibility of doing something like import * as PA from "projectA/components" because each component may load additional 3rd party libraries and importing all will also load all of the dependencies, when most of the times they are not needed. Do you have any other suggestion for this case? Regards, |
consider not including the .ts files in your package when you publish it. |
@mhegazy we face this during development. To give you a bit more context: the same team is responsible for the development and maintenance of more than a dozen typescript projects. To ease the development, the packages are linked, through npm link, in the development environment. So, removing the .ts files when we publish them is fine (we are already doing that) but it's not an option during development. The current setup works but the compiler performance is a serious handicap. On the top layer packages (those which depend on 8 or 9 other typescript packages) it seems the compiler goes through all the files and compiles them. I already had the chance to talk with @jmatthiesen about our problems with VS and VSCode. I'm available to show you guys our environment if you are interested. Best, |
i see. thanks for the clarification. Do not think there are other workarounds other than fixing this issue. |
+1 - I only see this when bundling my files using the node_modules is already excluded in tsconfig. |
@asfasdfasdfasdf angular2 is not bundled because the compiler is finding Currently we use TSC to bundle our code with the
|
Fixed by #7075 |
Actually, #7075 didn't resolve this. As I commented at #7075 (comment)
If you like, I can quickly add the change to resolve this issue later this evening. I just didn't want to conflate the two and risk not getting in the other fix if the were concerns on this issue (as there had been some discussion above). Let me know. |
@billti What about source files found under |
@mhegazy this bug still exists in the visual studio 2015 plugin (the 2.0 release). For example if you have the |
This is mainly about compiling them not about finding them. |
Are these .ts files being compiled with your project? |
they are not being compiled. I use a but the auto-error-detecting service in visual studio gets confused by the |
this is also probably related to |
That the tsc command generated the js files of ts sources in node_modules folders was for us actually a feature and not a bug! This worked fine in 1.8.10 but no longer in 2.0.3. Our npm packages didn't contain the compiled js files, only the ts source files. Any chance that this "bug" could be reopenend and enabled again? Maybe optionally with a tsc option ? |
@AngeloSalvade you can still explicitly include those source files via the various include/exclude files settings in tsconfig.json if you want them part of the program. That should work fine. |
I already tried this and included "node_modules/*/". There are no errors. However, there are no generated JavaScript files for the TypeScript sources in the node_modules folder. I used "module": "commonjs". |
@billti I've provided a very short project https://github.com/softappeal/demo6964 showing my setup. |
I took a quick look. Modules resolved by searching under |
I updated the project with your suggestion. It still doesn't work. Setting maxNodeModuleJsDepth to a higher value or setting outDir also didn't help. |
Looks like you're right - I just tried it and can't get it to work. I'll need to debug through it and figure out what's going on here. I already fixed this exact scenario explicitly once (see discussion history at #9542 ), and as I pointed to above, there is a test case to cover it, so I'll need to dig in deeper. Thanks for reporting! Sorry for the inconvenience. |
OK. Looks like this is still as intended, and my memory is rusty. The compiler still defaults to excluding node_modules, bower_components, etc... if no specific In fact, if you specify an exclude, then we default to all files in all folders (if Another (separate) point which may be just in your sample, but for your module you have no Hope this clears things up! I'll try and get it documented a little clearer. |
Note: Per our docs at http://www.typescriptlang.org/docs/handbook/tsconfig-json.html:
That last sentence seems to cover it. |
@billti Thanks a lot for your fast help. After replacing include with exclude, it works as I hoped. I updated the project. And yes I now about the main property. I just left it out because it was not important for showing the effect. |
I uncovered this general issue while testing loading JavaScript files from
node_modules
, but realized (and confirmed) this applies to TypeScript files also.Basically, when we search the
node_modules
folder, we look for all supported extensions and add them to the compilation. Currently this means that if we find a TypeScript file in a Node module (e.g. someone published their package including the source), then we compile this also.For example, if module
sausages
was published as follows (with the original source besides the compiler files):Then we get the benefit of loading the
.ts
and getting the types from this. However on compiling an app which uses thesausages/core
module, withoutDir: "out"
, I get the resulting output (notice howcore.js
from thesausages
package has been compiled into anode_modules
folder in myoutDir
).I already added a flag to denote if a file was found by searching Node modules in this pull request. I can refactor this to eliminate this issue if that seems reasonable.
The text was updated successfully, but these errors were encountered: