-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Prevent reading all node_modules
when using [untyped]
#7431
Comments
node_modules
node_modules
when using [untyped]
One could do the following;
|
Standard is just to use flow-typed which can help you stub any definitions that don't exist in flow-typed. Then you can safely ignore all of node_modules which solves performance issue and module resolution. |
@Brianzchen I don't understand why that would be the standard recommendation. This would prevent library authors from including useful Flow type definitions in their npm packages. Surely this could only hurt flow's adoption? In my experience, flow-typed is useful but not adequately complete. |
flow-typed will solve the immediately issue of performance and not being able to resolve anything. I should have been more thorough in explaining though. You're right this would stop library developers from shipping flow types, which is why flow also comes with exclusions for ignores which you can read about here, https://flow.org/en/docs/config/ignore/ (at the bottom of the page) So your flow config would look something like
To my knowledge flow has no way of knowing if a package ships with flow types, so it has to be a manual process. My recommendation is that if flow-typed stubs the library, you should check if it ships with flow types. Hope this was an appropriate explanation. |
Thank you, that is helpful. Still, though, this seems like a workaround, not a solution. Manually declaring how to handle the types for every dependency is tedious, if nothing else. Again, this feels like a barrier to adoption. I have found that using It seems that there should be some solution that flow could implement to improve the performance. Perhaps this needs to be a separate ticket, but it seems very important to me. |
@vjpr @murrayju it's too bad this issue was closed as I agree with you both there should be just a single line of config to address this issue. Here's my workaround, 2 lines of config per node_module you need to import:
|
I want
import 'foo/bar'
to not throw "cannot find module" errors, but want to prevent the server looking at all mynode_modules
.With the current options there is no way to get this to work.
a.
Problem: Dramatically slower server startup.
This makes the server scan all my
node_modules
. I have ~3000 project files, and 200K files innode_modules
.This means the server takes 1 minute to start versus instantly.
Instead of needing to read and watch every node_module file to ensure
import 'foo/bar'
is valid, just check whether the files exist during type checking process. But I would be fine with just ignoring the check of whether my imports are valid for node_modules too.b. ignore
Problem: "Cannot find module" errors for any
import foo from 'foo'
.c. ignore all node_modules except first level of dirs
(Ignore all node_modules dirs except the first)
Problem:
import 'foo/bar'
doesn't work.d. declarations
Problem: Still slow server startup - scans every file.
Problem: Errors are shown for all 3rd party modules with type annotations of which there are usually hundreds broken (e.g.
graphql@0.13.2
). This will happen perpetually because there will always be deprecations and new features, and flow doesn't have a way to version type annotations.e. name_mapper for all non-relative requires
any.js.flow
Doesn't scan or watch any node_modules. All package imports will be replaced with
any
type - just liked[untyped]
does.Problem: This doesn't work with a monorepo where
import foo from 'foo'
could refer to a symlinked package.Problem: It's not flexible.
Solution
Add an option
module.system.node.silence_module_not_found_errors_in_ignore_paths
or something like that.Related
The text was updated successfully, but these errors were encountered: