Ask questionsUnable to access module with well_formed_exports
<!-- Please fill out this entire template so that we can address your bug report as quickly as possible.
Any bug reports that don't contain instructions to reproduce the issue will be closed. -->
Code like this:
let importBase = typeof module !== undefined ? module.id : __module
should be allowed
module may only be used as part of a legal top level export statement [invalid-export]
<!-- Please reproduce your issue on flow.org/try so that we can debug it.
Not all issues are reproducible on try-flow because they may require multiple files or specific flowconfig settings. If your bug can only be reproduced under one of these constraints, please make a small github repo that contains a minimal way to reproduce your problem. -->
We (unfortunately) have a lot of such imports in our project and I would not be able to enable types-first without changing it in some way (like with Babel macro). I think it's a part of the bigger issue where you cannot access module properties (or even test for its presence) in any way and I believe it should be allowed. We don't use module.exports anywhere in the flow checked files so we don't even need flow to scan for it, we just need module ID to track imports for hot reloading and it's not possible to do with
Answer questions dsainati1
well_formed_exports is essentially checking that the type of each module is completely determined by syntax, and does not rely on any code execution, and can thus be inferred statically. Code like you have above violates this assumption, which is why it is an error. This is working as intended.