pmndrs / react-spring

✌️ A spring physics based React animation library
http://www.react-spring.dev/
MIT License
27.73k stars 1.18k forks source link

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

Open DoxasticFox opened 5 months ago

DoxasticFox commented 5 months ago

Which react-spring target are you using?

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