-
Notifications
You must be signed in to change notification settings - Fork 70
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
Invariant can't be imported in TypeScript under jest vs metro-bundler/packager (in react-native) #32
Comments
@fbartho do you have babel in your build config? I have no problems with jest, because I have ts transpiler only, when I use it with webpack ts and babel, then I have an error invariant is not a function. |
@maciejw Yes. I have both babel and webpack as I'm using ReactXP to target both web & react-native. |
I have been able to work around this in our project by porting the code to TypeScript. Not sure if anybody would want that. |
ok I have some info regarding subject.
this is how invariant is exported
so bundler should shim it, this could be configuration issue, as a workaround require can be used, and then reexport using es6 syntax. or we can PR this if this last solution is OK :) |
Prior to TypeScript 2.7, CommonJS modules that exported a function as the module (i.e. This changed in TypeScript 2.7 with the introduction of This boils down to:
|
I had to use |
Using invariant imported with the following two patterns fails opposite depending on how we run the build (either as unit-tests under jest, or as a react-native view on android).
Swapping the import from one to the other enables/disables using invariant in the opposite target.
The text was updated successfully, but these errors were encountered: