flow v0.57.x don't shows no errors if use `module.system.node.resolve_dirname=src`
I need help!
flow don't show any errors, if write module.system.node.resolve_dirname=src in .flowconfig
https://github.com/gin0606/flow-v0.57.1-trouble
Please see this repository, that can see my trouble.
Thanks!
Maybe related to https://github.com/flowtype/flow-bin/issues/91 and https://github.com/facebook/flow/issues/5105
Still an issue with 0.58.0
I'd encountered the same problem, and dug down into a code of the Flow, then I think that I found what the reason it caused.
First, in version 0.57 of Flow, the feature as described below added
New Features: Flow will now only check the files in node_modules/ which are direct or transitive dependencies of the non-node_modules code.
Also, the document explains about setting module.system.node.resolve_dirname as below.
module.system.node.resolve_dirname (string) By default, Flow will look in directories named node_modules for node modules. You can configure this behavior with this option.
In other words, adding a setting to resolve_dirname means that a directory added will not be checked as well as node_modules unless imported from the file where not in the directory set to resolve_dirname and not set to the ignore option.
As far as the document explained, I think this behavior may be the intended of the Flow team. But it will confuse some users, including me.
My workaround is to import files where Flow check lazily, from files where Flow check immediately
For example, in case of @gin0606 https://github.com/gin0606/flow-v0.57.1-trouble, we will be able to force type checking by placing the file like below in the root directory of the repository.
// ./src/index.js
// @flow
import bar from 'foo/bar';
let num: number = 1;
let numerror: number = 'string';
let string: string = bar();
console.log(num);
console.log(numerror);
console.log(string);
+
+ export default () => {};
// In root of repository ./root.js
+ import fn from "./src"
But the workaround seems not absolutely ideally.
My personal opinion is that it should be checked lazily node_modules directory only.
Because some users use resolve_dirname option conjunction with resolve.modules option of the Webpack.
If we need PR to make such corrections, I will be honored to make it.
However, for us to find an ideal solution about this, I would like to hear the opinion of the Flow team on this Issue especially @gabelevi 's one (because he added such feature in https://github.com/facebook/flow/commit/385da8e95b3d7e759f8419b8b86216a9aa9f8f42).
I actually implemented a workaround for this problem. It doesn't keep the exact same behavior but you get your errors back in the case described by the OP:
Simply change:
module.system.node.resolve_dirname=src
to
module.system.node.resolve_dirname=./src
It will not give you the bubble effect but it will let you use your base directory for all imports

Thanks @kogai !
For our project we've just replaced module.system.node.resolve_dirname=src with several module.name_mapper, like this:
module.name_mapper='^desktop/\(.*\)$' -> '<PROJECT_ROOT>/src/desktop/\1'
And it seems that it fixed the issue.
On the project I am using now the relative url definitely fixes the issue.
I'd like to echo the question from @kogai.
We are using Flow in a fairly large project, with the module.system.node.resolve_dirname rule pointing to our local source code.
Maintaining a list of individual name_mapper rules is going to be quite unwieldy and error prone. Converting every import statement to a relative import will also be difficult at this stage, and seems likely to increase the fragility of our codebase.
It would be great to hear the flow team's thoughts on this issue, and investigate possible alternatives.
Experiencing the same issue. But here is the weird thing: on OSX it works perfectly fine. On our CI (Travis, Ubuntu 14.04.5 LTS) it fails to output any errors.
Unfortunately the workaround of a list of name_mapper rules doesn't work. Maybe a difference with others is that we run flow check with the --all flag.
@qamil I had the same issue just yesterday, and although I know that it probably won't help everyone, I made CI checking work by changing module.system.node.resolve_dirname=src to module.system.node.resolve_dirname=./src
Any idea why the ./ trick works? Thanks to @bradennapier I've now got this:
[options]
module.system.node.resolve_dirname=node_modules
module.system.node.resolve_dirname=./app
...and it works great – Flow skips checking non-depended files within node_modules, but it always checks everything in app, which is what I want.
But I'm concerned this might be an unsupported hack, that it might get 'fixed' in a future Flow version and stop working. Is the ./ trick an approved way to opt-out of the 0.57.0 new feature, or is there a better method that is sanctioned by the Flow team?
I think you can find the answer here: https://github.com/facebook/flow/issues/5647
@callumlocke It seems like it works for me as well (with Flow 0.66.0), thanks!
@alexeyraspopov I can't see an answer to my question there. Can you be more specific?
@callumlocke, do not use resolve_dirname for your code. Use name_mapper instead.
@alexeyraspopov can you point to where a Flow team member has said this is the better course of action? Or some official docs saying this?
My app has a lot of subdirs. Using several name_mapper lines (one for each subdir under app) is more complex, and a bit harder to maintain (need to remember to update the flow config whenever our directory structure changes). So before doing that, I want something official.
@alexeyraspopov you are right, usage of module.name_mapper is the correct solution. It's a pity that it is not clear from the official documentation especially when module.system.node.resolve_dirname was commonly used for aliases.
@callumlocke for every folder under src add the following line to [options] section of your .flowconfig file:
module.name_mapper='^my_folder/\(.*\)$' -> '<PROJECT_ROOT>/src/my_folder/\1'
BTW now I think this issue can be closed... :)
can you point to where a Flow team member has said this is the better course of action? Or some official docs saying this?
This is why my issue exists. Docs need improvements to emphasize this part.
@callumlocke I agree that it is harder to maintain but the official documentation (https://flow.org/en/docs/config/options/#toc-module-system-node-resolve-dirname-string) says that module.system.node.resolve_dirname should be used for specifying of node modules location. Using it for aliases of our modules was kind of hack I think.
@JakubRimal @alexeyraspopov OK, I have PR'd a docs update. Please go and upvote it if you agree: https://github.com/facebook/flow/pull/5850
This issue is also being tracked at https://github.com/yahoo/react-intl/issues/1086
module.system.node.resolve_dirname should be used for specifying of node modules location. Using it for aliases of our modules was kind of hack I think.
Right, it's bad that this hack is the only sane way to make flow work as expected right now.