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

ES6 import statements breaks Jest with TS #446

Open
AllanZhengYP opened this issue May 26, 2023 · 2 comments
Open

ES6 import statements breaks Jest with TS #446

AllanZhengYP opened this issue May 26, 2023 · 2 comments

Comments

@AllanZhengYP
Copy link

Although ES6 imports work with React Native bundlers, Jest does not support it natively.

Recently I introduced this package to our library. It works perfectly in RN integration test but

  • it breaks our unit test using Jest and:
  • all the consumers that does NOT mock our library.
/home/runner/work/amplify-ui/amplify-ui/node_modules/react-native-url-polyfill/auto.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import {setupURLPolyfill} from './index';
                                                                                             ^^^^^^

    SyntaxError: Cannot use import statement outside a module

I have (aws-amplify/amplify-js#11411) to workaround it by vendoring a bundle that transpiles this package to CommonJS module.

According to the Node.js doc on the dual module packages, historically the main is entry point for the CommonJS module and module is the entrypoint for the ES6 modules.

I think this repo should use the CommonJS require, or at least change the main to point to a CommonJS module version of it.

I can contribute a PR if we agree this is the right direction.

@charpeni
Copy link
Owner

It sounds right, thank you!

Will be happy to review.

@AllanZhengYP AllanZhengYP changed the title ES6 import statements breaks Jest ES6 import statements breaks Jest with TS May 29, 2023
@dannyBies
Copy link

As part of updating my Expo app to SDK 49 I also updated this package to version 2.0.0. After doing this I started running into this issue as well. If I only downgrade this package back to 1.3.0, my tests pass.

image

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

No branches or pull requests

3 participants