Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metro bundler says that runtypes has require cycle #289

Closed
iyegoroff opened this issue Nov 1, 2021 · 2 comments
Closed

Metro bundler says that runtypes has require cycle #289

iyegoroff opened this issue Nov 1, 2021 · 2 comments
Labels

Comments

@iyegoroff
Copy link
Contributor

Metro output:

 WARN  Require cycle: node_modules/runtypes/lib/index.js -> node_modules/runtypes/lib/types/unknown.js -> node_modules/runtypes/lib/runtype.js -> node_modules/runtypes/lib/index.js

Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
@yuhr
Copy link
Collaborator

yuhr commented Nov 2, 2021

Sorry, essentially it's not possible to remove the cycle. Each runtype such as Unknown needs to use the internal create function defined in runtype.ts, and the create function needs some of those runtypes in order to implement the utility functions like .optional() and .withConstraint(). Actually it might be possible if we put all the codebase in a single bloated file, but absolutely we don't want. I think bundlers have to be completely okay to work with circular imports.

It's a valid semantics in ECMAScript, however, we're currently transpiling only with "module": "commonjs" option. ESM support is definitely what we should add. Also, we can add some auxiliary configurations like "sideEffects": false in package.json, which would help bundlers to work.

Essentially this is a wontfix though, let's leave this issue open until the warning disappears after some configuration. Maybe #243 is also worth tracking.

@yuhr yuhr added the build label Nov 2, 2021
@iyegoroff
Copy link
Contributor Author

Thanks for the detailed explanation!
I tried to fix this myself, but understand that it hardly possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants