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
flow v0.57.x don't shows no errors if use module.system.node.resolve_dirname=src #5180
Reacted by James W Dunne, Samuel Martineau, Braden Napier, Dan Coates, Derek Dahmer, Shinichi Kogai, Adam Kuśmierz, Eelke Hermens, Stas Gavrylov, qamil and 29 more
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
// ./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 385da8e).
Reacted by Alexander Savin, Eelke Hermens, Andrew Hyndman and ugeng
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
Reacted by izumskee, Andrew Khantulin and jazozaya
Reacted by Callum Locke, Chad Wilson, Federico Zivolo, timmydoza, Laurens Kling, ravecat, ugeng, Xandor Schiefer, silen, Steve Kaschinske and 1 more
Reacted by Alberto Leal, Kristie Howard, Courtney Myers, erichartline, Pedro Moreira, Callum Locke, Ky Lee, Chad Wilson, Federico Zivolo, Tobias Poel and 10 more
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.
Reacted by Valentin Agachi, Theo Salzmann, Brent Hargrave, Shinichi Kogai, qamil, Max Salvén, Braden Napier, Todd Moore, Brett Statman, Joey and 13 more
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
Reacted by John Shammas, Kristie Howard, Nicolas Goutay, Will J., Callum Locke, Sirui Li, Harald Gliebe, Paul Collier, Cory Robinson and Stephen
...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?
Reacted by Sirui Li, Louis Roman, ugeng, Eric Walker and Thomas G Henry
Reacted by Tsotne Nazarashvili and Thomas G Henry
Reacted by JakubRimal, Louis Roman and Thomas G Henry
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.
Just one if you're doing components/. Yes, if you wanted to do all of them with no prefix, you'd have to write a mapper for every single directory. I wouldn't recommend that pattern anyway.
I just started encountering the same issue on flow 0.119.1
no errors are shown while there are several in the code. Changing a file will introduce some errors but the behavior is completely erratic
makes flow report every import for a file inside my project (under src) as unable to resolve.
Did anyone find a solution that doesnt include writing custom regex mapper for each folder in my src root?
Having to maintain a matching list of folders seems like a terrible way to go about keeping my code safe...
Activity
apsavin commentedon Nov 3, 2017
Still an issue with 0.58.0
kogai commentedon Nov 4, 2017
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
Also, the document explains about setting
module.system.node.resolve_dirnameas below.In other words, adding a setting to
resolve_dirnamemeans that a directory added will not be checked as well asnode_modulesunless imported from the file where not in the directory set toresolve_dirnameand not set to theignoreoption.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.
But the workaround seems not absolutely ideally.
My personal opinion is that it should be checked lazily
node_modulesdirectory only.Because some users use
resolve_dirnameoption conjunction withresolve.modulesoption 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 385da8e).
bradennapier commentedon Nov 4, 2017
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:
to
It will not give you the bubble effect but it will let you use your base directory for all imports
apsavin commentedon Nov 4, 2017
Thanks @kogai !
For our project we've just replaced
module.system.node.resolve_dirname=srcwith severalmodule.name_mapper, like this:module.name_mapper='^desktop/\(.*\)$' -> '<PROJECT_ROOT>/src/desktop/\1'And it seems that it fixed the issue.
bradennapier commentedon Nov 4, 2017
On the project I am using now the relative url definitely fixes the issue.
ajhyndman commentedon Nov 13, 2017
I'd like to echo the question from @kogai.
We are using Flow in a fairly large project, with the
module.system.node.resolve_dirnamerule pointing to our local source code.Maintaining a list of individual
name_mapperrules 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.
qamil commentedon Nov 14, 2017
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 checkwith the--allflag.stasgavrylov commentedon Nov 14, 2017
@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=srctomodule.system.node.resolve_dirname=./srcUpdate README.md
chore: Update README.md (#237)
callumlocke commentedon Feb 19, 2018
Any idea why the
./trick works? Thanks to @bradennapier I've now got this:...and it works great – Flow skips checking non-depended files within
node_modules, but it always checks everything inapp, 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?alexeyraspopov commentedon Feb 19, 2018
I think you can find the answer here: #5647
JakubRimal commentedon Feb 19, 2018
@callumlocke It seems like it works for me as well (with Flow 0.66.0), thanks!
callumlocke commentedon Feb 19, 2018
@alexeyraspopov I can't see an answer to my question there. Can you be more specific?
alexeyraspopov commentedon Feb 20, 2018
@callumlocke, do not use
resolve_dirnamefor your code. Usename_mapperinstead.3 remaining items
JakubRimal commentedon Feb 20, 2018
@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_dirnameshould be used for specifying of node modules location. Using it for aliases of our modules was kind of hack I think.callumlocke commentedon Feb 20, 2018
@JakubRimal @alexeyraspopov OK, I have PR'd a docs update. Please go and upvote it if you agree: #5850
callumlocke commentedon Feb 21, 2018
This issue is also being tracked at formatjs/formatjs#1086
dgcoffman commentedon Mar 5, 2018
Right, it's bad that this hack is the only sane way to make flow work as expected right now.
TrySound commentedon Mar 6, 2018
Resolving modules from directory is a hack itself. It's not expected by browser or node.
STRML commentedon Mar 6, 2018
MaxInMoon commentedon Mar 6, 2018
Just a question to be sure to understand:
If I have 60 components in
src/components/like so:Do I have to write 60
name_mapperlines like:module.name_mapper='^Button\/\(.*\)$' -> '<PROJECT_ROOT>/src/components/Button\1'In order to import a component like:
import Button from 'Button';??
It is possible to do like so?
import Button from 'components/Button'?
Thanks in advance
STRML commentedon Mar 6, 2018
Just one if you're doing
components/. Yes, if you wanted to do all of them with no prefix, you'd have to write a mapper for every single directory. I wouldn't recommend that pattern anyway.leethree commentedon Jun 28, 2018
@stasgavrylov 's workaround (#5180 (comment)) works for us. But we would really like this issue to be fixed officially by Flow.
crobinson42 commentedon Aug 2, 2018
The flow config option
module.system.node.resolve_dirname=srcis still not documented as of version0.77- but the./srcsolution is working.eddig commentedon Oct 14, 2018
The
module.system.node.resolve_dirname=./srcdoesn't work on0.83.0vjpr commentedon Nov 3, 2018
module.system.node.resolve_dirname=./srcworks for me in0.85.0. This is my scenario:modules/foo/index.jswas not getting type-checked.Changing to
module.system.node.resolve_dirname=./modulesmade it be type-checked.In future, I will use
require('modules/foo')for my aliases and use thename_mapper.yoavniran commentedon Mar 8, 2020
I just started encountering the same issue on flow 0.119.1
no errors are shown while there are several in the code. Changing a file will introduce some errors but the behavior is completely erratic
Using:
module.system.node.resolve_dirname=./srcinstead of:
module.system.node.resolve_dirname=srcmakes flow report every import for a file inside my project (under src) as unable to resolve.
Did anyone find a solution that doesnt include writing custom regex mapper for each folder in my src root?
Having to maintain a matching list of folders seems like a terrible way to go about keeping my code safe...