react native - Flow saying "Required module not found" for <Image> sources -
we have existing react native project (version 0.22.2) , i'm trying set flow type checker (version 0.23) on files. however, flow giving lot of errors require()
s calls we're using <image>
sources. example, have code in 1 of our components in header.js:
<image source={require('./images/nav.png')} style={styles.navicon} />
which react native handles fine , works. however, flow seems trying treat require()
regular module require , not finding it, , giving errors this:
header.js:30 30: <image source={require('./images/nav.png')} style={styles.navicon} /> ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ./images/nav.png. required module not found
how can tell flow stop giving these errors? i've tried adding .*/images/.*
[ignore]
section of .flowconfig
, doesn't change anything.
you can use module.name_mapper.extension
option in .flowconfig. example,
[options] module.name_mapper.extension= 'png' -> '<project_root>/imagesourcestub.js.flow'
which map module name ending in .png
imagesourcestub
module, if instead of writing require('./foo.png')
had written require('./path/to/root/imagesourcestub')
.
in imagesourcestub.js.flow
can do
const stub = { uri: 'stub.png' }; export default stub; // or module.exports = stub;
so flow knows require('*.png')
returns {uri: string}
.
see advanced configuration docs.
Comments
Post a Comment