Skip to content

Instantly share code, notes, and snippets.

@ryancat
Created July 10, 2017 15:23
Show Gist options
  • Save ryancat/d4b1521f82a30b9a1354df1280daade9 to your computer and use it in GitHub Desktop.
Save ryancat/d4b1521f82a30b9a1354df1280daade9 to your computer and use it in GitHub Desktop.
Fix flow import style issue
GOAL:
Make flow understand *.css files and map them to an exported Object or whatever type you need... also to prevent this dreaded module not found error.
STEPS:
In your project folder, create a file helpers/CSSModule.js with following content:
//@flow
export default {};
Now tell flow in your .flowconfig that you want to redirect all *.css require / imports to your newly created helpers/CSSModule.js file:
[ignore]
[include]
[libs]
[options]
module.file_ext=.css
module.file_ext=.js
module.file_ext=.jsx
module.file_ext=.json
module.name_mapper='.*\.css$' -> './helpers/CSSModule'
Restart your flow with flow stop && flow start
RESULT:
Now everything is set up... let's assume we have a file test.js and whatever.css in the same directory:
// whatever.css
div {
color: blue;
}
// test.js
//@flow
import styles from './whatever.css';
styles will now be of type Object, since I mapped it to the CSSModule export instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment