Skip to content
This repository has been archived by the owner on Oct 19, 2020. It is now read-only.

3dio.js can't be bundled with React Native because of dynamic requires #89

Open
bnjm opened this issue Oct 19, 2017 · 2 comments
Open
Labels

Comments

@bnjm
Copy link
Contributor

bnjm commented Oct 19, 2017

The bundler for React Native (https://github.com/facebook/metro-bundler) does not support dynamic require's and as of RN 0.49 throws the error require() must have a single string literal argument if you include 3dio.js in the project.

This caused a problem for other libraries like moment.js ( facebook/react-native#16216), resulting in a PR to alias require as a work around (moment/moment#4187)

Environment

React Native 0.49.0-rc.6
metro-bundler 0.13.0
3dio.js 1.x.x

How to reproduce:

npm install 3dio
import '3dio' in a React Native project.

Result:

Error gets thrown at compilation time require() must have a single string literal argument

Since this was an unexpected breaking change there's a good chance a patch in metro-bundler will be released (facebook/metro#65), however from the discussion it also seems like there are valid reasons not to support dynamic requires

@bnjm bnjm added the glitch label Dec 13, 2017
@bnjm bnjm self-assigned this Dec 13, 2017
@ethantran
Copy link

ethantran commented Dec 22, 2017

Any way around this? I am trying to use this on expo with threejs.

@bnjm
Copy link
Contributor Author

bnjm commented Dec 27, 2017

Discussed this with @tomas-polach, the temporary proposed solution was to fork the repository and fix it there.

I've done this here: https://github.com/bnjm/3dio-js/

You can install it like yarn add bnjm/3dio-js

I haven't tested it with THREE.js yet. Out of curiosity is this the bridge you are using for THREE.js with RN?
https://github.com/react-community/react-native-webgl

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

No branches or pull requests

2 participants