microsoft/nova-facade

nova-facade-react: `import invariant form "invariant";` to ensure it works in web and react native.

tom-un opened this issue · 3 comments

In TMP, the nova-facade-react package depends on invariant and imports the default as invariant:

e.g.
import * as invariant from "invariant";
https://domoreexp.visualstudio.com/Teamspace/_git/teams-modular-packages?path=%2Fpackages%2Fnova%2Ffacade%2Fnova-facade-react%2Fsrc%2Fgraphql%2Fhooks.ts&version=GBmaster

When this code is used in react-native bundles, the result is an object named invariant instead of a function named invariant (see zertosh/invariant#32).

For the code to work in web and react native, the imports should change to
import invariant from "invariant";

In 1JS, I patched nova-facade-react with this change and verified it works in both web and native. https://office.visualstudio.com/Office/_git/1JS/pullrequest/978506

Oddly, updating the reference like above breaks the unit tests in TMP with the following error. TypeError: invariant_1.default is not a function

Hopefully this won't be an issue in this repo.

Could TMP's TS config be missing the allowSyntheticDefaultImports: true as referenced in zertosh/invariant#32 ?

This should be done in the initial package commit.