Open samwgoldman opened 8 years ago
The issue appears to be here, where we assume that an import can be resolved on the FS (but neglect to deal with the fact that an import might be made available in a libdef's declare module
).
It also appears that you can't map to lib files. If you take the example from the docs and add CSSModule.js.flow
to [libs]
then you get an error. https://gist.github.com/a879ca861671edb16143d4b20ea8526e
Following #1621, here is my flow config https://github.com/MoOx/js-boilerplate/blob/4797f86049d87f013b9cab60480d5c954c1f24a8/.flowconfig
And the CSSModule definition is defined in node_modules/flow-interfaces/interfaces/CSSModule.d.js
(it's this one https://github.com/TechnologyAdvice/flow-interfaces/blob/20fc1a5439803523fd3d3cf338619e58e81fc13b/interfaces/CSSModule.d.js)
Probably related https://github.com/facebook/flow/pull/1801#issuecomment-219719511
Still seeing issues with this out of the box. Using the docs,
module.name_mapper.extension='css' -> '<PROJECT_ROOT>/CSSFlowStub.js.flow'
makes Flow treatrequire('foo.css')
as if it wererequire(PROJECT_ROOT + '/CSSFlowStub').
Nope.
4: require('./Input.css');
^^^^^^^^^^^^^^^^^^^^^^ ./Input.css. Required module not found
@kevinSuttle did you create CSSFlowStub.js.flow file? Please take a look at this https://stackoverflow.com/questions/36912675/flow-required-module-not-found
That helped. Thanks @MoOx.
It would also appear that you can't map to a flow file in flow-typed
.
When I do module.name_mapper='^\(.*\)\.css$' -> '<PROJECT_ROOT>/config/flow/css'
, it works (no errors on importing a css file), but when I have module.name_mapper='^\(.*\)\.css$' -> '<PROJECT_ROOT>/flow-typed/css'
, it complains about "required module not found".
I suppose it makes sense to not look for them in flow-typed
, kinda, but it was confusing.
I just got tripped up by this as well. Putting the declaration in the flow-typed
directory was my first thought. I eventually found this thread and moved my .scss
stub file to a different directory and it worked.
Is the plan to support name_mapping to a declaration in flow-typed
? Or should I continue to expect having to declare those in a different directory? Thanks.
Ran into the same thing. My first instinct was to place it in flow-typed
, but that did not work.
Flow seems to be a bit picky about the location of the stub files. I had them in a folder __mocks__
where I already had stub / mock files for different purposes and flow did not pick up the stub files, leaving me with the "required module not found" error. After putting the stubs in a folder named flow-stubs
, it worked.
I have filed an issue here: #3687
Wow, that's quite an old issue.
Did someone found a workaround when you need to remap a path from one file to another, without using an additional NPM package?
Repro:
.flowconfig
A.js
lib/Exists.js
Expected output:
Actual output:
Workaround: While libdefs aren't working, it's still possible to map to a node module. There's an npm module called
empty
that can be useful here. See this gist for a complete example.I think the issue is that we do name mapping specifically against file paths, so the code just doesn't attempt to handle this case. I think that it should. cc @jeffmo, who originally added this feature.