profile
viewpoint

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. -->

Flow version:

Expected behavior

Code like this:

let importBase = typeof module !== undefined ? module.id : __module

should be allowed

Actual behavior

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. -->

  • Link to Try-Flow or Github repo: https://github.com/tutao/flow-module-export

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 well_formed_exports.

facebook/flow

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.

useful!

Related questions

Common spread pattern leads to "exponentially large number of cases" errors hot 1
Flow issue "Please upgrade flow to version >=0.75." hot 1
Object.fromEntries type defs missing hot 1
Cannot set defaultProps with React.memo and React.forwardRef hot 1
Inexact rest object claims it may have properties it can't possibly have hot 1
Inexact rest object claims it may have properties it can't possibly have hot 1
Inexact rest object claims it may have properties it can't possibly have hot 1
0.92.0 release crashes on startup (Unix.Unix_error) hot 1
module.name_mapper does not find nested modules on windows hot 1
Cannot import useState because there is no useState export in react. hot 1
Can't use a default value from a destructuring assignment as a computed property since 0.111 hot 1
Support optional chaining - flow hot 1
Flow issue "Please upgrade flow to version >=0.75." hot 1
Allow explicitly including a folder under an ignored path hot 1
Flow caches and fails to purge errors hot 1
source:https://uonfu.com/
Github User Rank List