-
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
Remove module.name_mapper.extension
from docs
#1801
Conversation
I am using flow 0.25 and this does not works as I am getting this error ``` .flowconfig:20 Unsupported option specified! (module.name_mapper.extension) ```
Hmm that's odd, this is supposed to work... (See https://github.com/facebook/flow/blob/master/src/common/flowConfig.ml#L455) Can you post your full .flowconfig so I can try and repro? |
Note that I found several comment "on the internet" (github threads, stackoverflow, gist comments) of people reporting this exact same error message with flow 0.22+ But please, don't laugh: I play maybe too long with flow config and I cannot reproduce. Want I want is simple: I use webpack and so "import" some CSS and png so I tried something like this: [ignore]
.*/node_modules/.*
.*/lib/.*
.*/.nyc_output/.*
.*/__tests__/.*
[include]
node_modules
[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='.*\.css$' -> 'CSSModule'
module.name_mapper='.*\.(svg|png|jpg|gif)$' -> 'string' The only 2 interesting lines are the last ones. This does not work as expected as I am getting this kind of errors.
I think most people are stuck in this step. You define a mapper rule but it does not (seem to) work. After some reading some comments everywhere I found this module.system=haste Using this, some error are gone (all the one related to .css files). I read somewhere else (and I think in a previous issue @samwgoldman told me this too) that this is not a good idea to use So I removed this line and found module.file_ext=
module.file_ext=.js
module.file_ext=.json This is the same thing I am using in my webpack config to allow me to import/require other files extensions like css and svg: resolve: {
extensions: [ "", ".js", ".json" ],
} So with this flow config ###
# Webpack config adjustements
###
## allow no extensions
## to be able to import .css,svg,png ...
module.file_ext=
module.file_ext=.js
module.file_ext=.json
## loaders
module.name_mapper='.*\.css$' -> 'CSSModule'
module.name_mapper='.*\.(svg|png|jpg|gif)$' -> 'string' I still have one issue
And only But back to module.name_mapper.extension='css' -> 'CSSModule'
module.name_mapper.extension='svg' -> 'string'
module.name_mapper.extension='png' -> 'string' And now it works (EXCEPT the last issue about the css in node_modules folder, but I guess it's a resolution issue, not an issue related to the So maybe in the first place, my issue were not using the appropriate version (I have PROPOSAL: If my config is correct (the one using an empty PS: If you have a tip to avoid having the |
I also found something weird: if I remove all the config about name_mapper and only keep the |
Some example of people having issue without |
I am closing this PR, but I really thing there is definitely an issue somewhere |
Wow thanks for such a detailed explanation! Ok, so let me break it down a little bit:
Yea, writing raw name_mappers is definitely confusing (mostly because we use OCaml's regexp syntax -- which is a little confusing and easy to mess up). This is why I added the
Ok, so I expect that what's going on here is that you're mapping to a global module name (not a path to a module -- which is how node module resolution works). Long Story Short:So if you want to map all .css files to a module that sits under
You can think of name_mappers as just a raw search/replace in your source code that happens just before Flow reads the code. So if you were mapping import "react-intl-tel-input/dist/main.css"; and it would tweak it to this: import "CSSModule"; The problem is that, in node, "CSSModule" means a package named "CSSModule" (not a file). As such, you probably just need to use the
This config option just lets you tell Flow to find files with an extension other than |
Thanks for the explanation I think I get it now. |
Now I get it :) #1068 (comment) |
I am using flow 0.25 and this does not works as I am getting this error