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

[bug]: Dynamic require of "react-native" is not supported on react native web #2250

Open
1 of 5 tasks
DoxasticFox opened this issue Jan 26, 2024 · 4 comments
Open
1 of 5 tasks
Labels
template: bug This issue might be a bug

Comments

@DoxasticFox
Copy link

DoxasticFox commented Jan 26, 2024

Which react-spring target are you using?

  • @react-spring/web
  • @react-spring/three
  • @react-spring/native
  • @react-spring/konva
  • @react-spring/zdog

What version of react-spring are you using?

9.7.3

What's Wrong?

This error appears in the browser console when importing '@react-spring/native' in react native:

Uncaught Error: Dynamic require of "react-native" is not supported
    node_modules bundle.js:60559
    node_modules bundle.js:60630
...

To Reproduce

  1. Initialize a new project, as described in expo's documentation.
  2. Run npm install @react-spring/native
  3. Add these lines to the generated App.tsx:
    import { useSpring, animated } from '@react-spring/native';
    
    // These ensure lazy loading doesn't prevent the import
    console.log(useSpring);
    console.log(animated);
    
  4. Start the app: npx expo start and press w to open your browser.
  5. The app will fail to load and the browser console will show the error: Uncaught Error: Dynamic require of "react-native" is not supported.

Expected Behaviour

No error.

Link to repo

https://github.com/DoxasticFox/react-spring

@DoxasticFox DoxasticFox added the template: bug This issue might be a bug label Jan 26, 2024
@giaset
Copy link

giaset commented Jul 31, 2024

Bumping this, as we're also dealing with this same issue

@joshuaellis
Copy link
Member

I've not looked at the example given, but we don't dynamically import react-native as far as I can see? So I'm confused how this is our error.

The error message provided also doesn't directly point to react-spring. Is there more information that can be shared?

@giaset
Copy link

giaset commented Jul 31, 2024

Hey @joshuaellis, thanks for the quick response.

Here's the full error from the console:

index.ts:24 Uncaught Error: Dynamic require of "react-native" is not supported
    at index.ts:24:1
    at ./node_modules/@react-spring/native/dist/react-spring_native.modern.mjs (index.ts:14:1)
    at __webpack_require__ (bootstrap:22:1)
    at fn (hot module replacement:61:1)
    at ./components/PressableWithHaptics.tsx (PressableText.tsx:28:1)
    at __webpack_require__ (bootstrap:22:1)
    at fn (hot module replacement:61:1)
    at ./components/Button.tsx (BottomSheetRedepositContent.tsx:120:1)
    at __webpack_require__ (bootstrap:22:1)
    at fn (hot module replacement:61:1)

The relevant line from index.ts looks like this:

    Globals.assign({
  batchedUpdates: require('react-native').unstable_batchedUpdates,
  createStringInterpolator,
  colors,
})

@ktml
Copy link

ktml commented Sep 9, 2024

I also have this issue with 9.7.0+. Downgrading to 9.6.1 fixed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
template: bug This issue might be a bug
Projects
None yet
Development

No branches or pull requests

4 participants