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

SyntaxError: Cannot use import statement outside a module #23

Open
a-eid opened this issue Oct 23, 2020 · 4 comments
Open

SyntaxError: Cannot use import statement outside a module #23

a-eid opened this issue Oct 23, 2020 · 4 comments

Comments

@a-eid
Copy link

a-eid commented Oct 23, 2020

seems that this lib causes the following error

import typeof AccessibilityInfo from './Libraries/Components/AccessibilityInfo/AccessibilityInfo';

Screen Shot 2020-10-23 at 11 33 15 AM

when commented out, the app works fine.

@a-eid
Copy link
Author

a-eid commented Oct 23, 2020

it's probably worth noting that this happens when running detox as seen in the above screen.

@Joelasaur
Copy link

I'm getting the exact same thing, which is supposedly used to fix a uuid issue here https://github.com/uuidjs/uuid#getrandomvalues-not-supported

@Joelasaur
Copy link

I fixed this issue by creating a new file called GetRandomValues.ts that looks like this:

export {};
declare let global: any;
global.crypto = {
  getRandomValues: (array: any[]) =>
    array.map(() => Math.floor(Math.random() * 256)),
};

Then in the original file where we are importing the uuid package:

import './GetRandomValues';
import { v4 as uuidv4 } from 'uuid';

Found the fix here uuidjs/uuid#416 (comment)

This doesn't solve the original issue with this library, but it's a workaround so that I'm not forced to encounter this bug when doing what's suggested in the uuid readme here https://github.com/uuidjs/uuid#getrandomvalues-not-supported

@LinusU
Copy link
Owner

LinusU commented Oct 31, 2022

@Joelasaur I would really not recommend using Math.random() to populate the values in getRandomValues since it's not cryptographically secure.

@a-eid The stack trace points to inside react-native, and not this module. Could you try to import something from react-native in your test, and not import react-native-get-random-values to see if this is an issue in this module, or an issue in React Native or Jest?

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