I'm having a folder structure:
modules/Test/js/main.js
modules/Test/js/nested/entry.js
a root test.js file:
/* @flow */
import main from '#Test/main';
import main2 from '#Test/nested/entry';
a name mapper:
module.name_mapper='^#\(.+?\)/\(.*\)$'->'<PROJECT_ROOT>/modules/\1/js/\2'
and it constantly throws Cannot resolve module #Test/nested/entry. Tried a bunch of other variants and nothing resolves the nested file. It finds #Test/main without any problems, but once it's a nested path, it does not recognize it.
This regex works fine with webpack and jest, e.g. jest:
"moduleNameMapper": {
"^#(.+?)/(.*)$": "<rootDir>/modules/$1/js/$2"
}
v0.81.0
Seems like a windows problem? it does resolve #Test/nested\\entry without any problems so I'm guessing it's folder separator problem. Any ways to overcome this?
Spent a while looking into this one and it turns out the \\ / Windows usage is a red herring. The root issue is that, unlike Webpack and Jest, OCaml regexp doesn't support non-greedy capture groups (.+?) - reference.
This example works if you change your name mapper to something like:
module.name_mapper='^#\([^/]+\)/\(.*\)$'->'<PROJECT_ROOT>/modules/\1/js/\2'
...otherwise it is rewriting your nested module name incorrectly, to modules\Test\nested\js\entry.js (nested and js wrong way round as the first capture group is greedy).
cc @avikchaudhuri
Closing as the Flow team don't have plans to move away from OCaml regex.
Sorry I missed notifications on this issue, @jamesisaac. I believe the Flow team is open to more JS-friendly configuration, and we've had some recent internal threads on this topic. I can't give a timeline but I'm optimistic that we will do something to avoid issues like this one.
Nice! I was just relaying what I heard on Discord the other week, but that sounds cool if you guys have plans around improved compatibility with the JS ecosystem.
While this issue's a good example of the confusion it can cause, I guess that's better tracked in something like #153 ? I'll make a note there.
I believe the Flow team is open to more JS-friendly configuration, and we've had some recent internal threads on this topic. I can't give a timeline but I'm optimistic that we will do something to avoid issues like this one.
For reference/easier findability, these are the flowconfig related issues/suggestions I found that would bring it in line with other tools like eslint, babel, webpack, etc:
.flowconfig.js.flowconfig should use json.flowconfig should recursively consider other .flowconfig filespackage.json
Most helpful comment
Spent a while looking into this one and it turns out the
\\/ Windows usage is a red herring. The root issue is that, unlike Webpack and Jest, OCaml regexp doesn't support non-greedy capture groups (.+?) - reference.This example works if you change your name mapper to something like:
...otherwise it is rewriting your nested module name incorrectly, to
modules\Test\nested\js\entry.js(nestedandjswrong way round as the first capture group is greedy).