-
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
module.name_mapper not working #1068
Comments
module.name_mapper
not working
This feature is covered by automated tests, which are still passing, so it's unlikely that the feature is wholesale not working. One thing that is suspicious about the code you've pasted here is the
|
I was surprised too! What else can I provide to debug this? maybe I should try cloning the source and running the unit tests on my machine? |
Ok, so I checked out the project and built it on my machine. All tests pass, but when I looked at the test sources, there are no tests for One of the tests that gets run is for the
I tried copying the code for that test to run it within my test app and sure enough flow finds the module in the I also verified that Here is the new source of my test app:
And here is the output of
|
Your regexp doesn't include '.' in the character class |
Tried fixing that too, it still didn't work:
BUT, it worked when I added this line:
Still, I think somebody should update the documentation because there are a few things here:
PS: another way to do this without using
|
Hypothesis: the name resolution works for modules found under |
It might be that. |
I'm still running into this; I'm attempting to map this:
This is with Flow v0.20.1 |
Ah, I worked it out. Turns out, it was working, but because |
+1 For this. I have same problem. |
I am also having issue with local png file [ignore]
.*/node_modules/.*
.*/lib/.*
.*/.nyc_output/.*
.*/__tests__/.*
[libs]
node_modules/flow-interfaces/interfaces
node_modules/iflow-material-ui/index.js.flow
node_modules/iflow-color/index.js.flow
flow-interfaces
[options]
esproposal.class_instance_fields=enable
esproposal.class_static_fields=enable
module.name_mapper='.*\.(svg|png|jpg|gif)$' -> 'string' and this code // @flow
import logoSVG from "./logo.png" .png are string, per webpack config (url-loader) |
Related: #1801 (comment) |
@jeffmo give some pretty good explanation here #1801 (comment) tl;dr: So this issue is just a bad usage.
I guess this issue can be closed now that there is enough material for people to understand this. |
Still not working in my case.
I get
|
I have the same issue:
import type { DataFieldT } from 'types/DataFieldT'
import * as fieldTypes from 'constants/fieldTypes'
import * as relTypes from 'constants/relationshipTypes'
import * as DFN from 'constants/dataFieldNames' I get:
Any suggestions? |
Seeing something similar here, after just installing Flow today and starting to play around with it. I'm trying to use Project structure:
.flowconfig:
Error:
Is this the same issue as the ones above? Any ideas? |
I was able to get around my issue with...
...which mimics my |
This kind of config still doesn't work for me: I'm not sure how to do it with I've resorted to creating symbolic links inside of |
Using flowtype 0.39.0 I encountered a similar problem with I'm doing: import isEmpty from 'lodash/isEmpty'; and I get this error: module.name_mapper='^lodash/.+$' -> 'lodash'
(* and *)
module.name_mapper='^lodash/\(.+\)$' -> '<PROJECT_ROOT>/node_modules/lodash/\1' but I always get the same error. Am I doing it wrong ? As I can't figured out what was wrong I just fallback to: import { isEmpty } from 'lodash'; |
My working solution for module resolving in 0.45:[options]
- module.name_mapper='^app\/(.*)$' -> '<PROJECT_ROOT>/app/\1' # does not work
+ module.name_mapper='^app\/\(.*\)$' -> '<PROJECT_ROOT>/app/\1' # works as expected
module.name_mapper='^i18n\/\(.*\)$' -> '<PROJECT_ROOT>/i18n/\1'
module.name_mapper='^lib\/\(.*\)$' -> '<PROJECT_ROOT>/lib/\1'
module.name_mapper='^mailer\/\(.*\)$' -> '<PROJECT_ROOT>/mailer/\1'
module.name_mapper='^schema\/\(.*\)$' -> '<PROJECT_ROOT>/schema/\1'
module.name_mapper='^mongoose-elasticsearch-xp\(.*\)$' -> '<PROJECT_ROOT>/lib/mongoose-elasticsearch-xp\1' Be careful with escaping characters in regexp Write this comment cause |
the same issue works fine with |
One more case: // module
import coverImage from './images/cover.jpg?preset=cover';
// .flowconfig
module.name_mapper='^\(.*\)\.\(png\|jpe?g\)\?preset=cover$' -> 'CoverImageModule'
// app/declarations/CoverImageModule.js.flow
declare module CoverImageModule {
declare var exports: {|
srcset: string,
fallback: string,
|};
} Works w/ Repo to reproduce: https://github.com/alexfedoseev/blog |
|
@Freezystem I'm having that same issue. Did you get is solved with resorting to importing just |
I used the fallback method by importing |
Same here. |
I can't seem to get name_mapper working either. I use webpack resolve.alias instead of using symbolic links (might have to use them?) to refer to a parent project. module.name_mapper='^react-native$' -> '<PROJECT_ROOT>/../react-evitan/src/components/index.js' I tried multiple ways with exact js, absolute paths, etc. If I substitute a known module, it does work. So to MoOx's point, is looking for modules only? Using ../ in an import works fine, so I would assume name_mapper would also. |
@mikeaustin coincidentally, I am trying to do exactly the same thing. I don't think you can use |
@jamietre Interesting. I guess I could use symlinks, but I don't think they work on Windows? Also, using webpack aliases allows all our imported components to see the alias. With symlinks, I'd need to add one in each module's node_modules. |
@jamietre Ensure |
I can't get this to work even with basic
Flow 0.50 |
Try |
As already mentioned by many, adding a separate It is not a good solution at all. Is there no simple way whatsoever for us to be able to specify a ROOT directory where our code is and leave it at that? This is clearly an ongoing problem and nothing seems to have been done about. I'm having no luck with Tried every permutation in this thread, There are just so many damn variables, and so many explanations that have too many knowledge dependencies to be able to understand. Nobody seems to have given a clear answer that overcomes to the burden of knowledge. Please just add a mechanism where I can say: this is my root directory, just use this damn directory. Considering it is build by Facebook, one should think there would be ample time and resources to improve it. |
I can't get module.name_mapper to work on the example in the documentation:
http://flowtype.org/docs/advanced-configuration.html#options
Flow version: 0.18.1
Folder structure:
Contents of
.flowconfig
:Contents of
ImageStub.js
:Contents of
app.js
:Here is the output when doing
flow check
:To make sure that the regex pattern wasn't the problem I tried to dumb it down and just do the following:
Contents of
.flowconfig
:Contents of
ImageStub.js
:Contents of
app.js
:and again, this is the output of
flow check
:Any ideas?
The text was updated successfully, but these errors were encountered: