3dio-js icon indicating copy to clipboard operation
3dio-js copied to clipboard

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

Open bnjm opened this issue 8 years ago • 2 comments

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 ( https://github.com/facebook/react-native/issues/16216), resulting in a PR to alias require as a work around (https://github.com/moment/moment/pull/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 (https://github.com/facebook/metro-bundler/issues/65), however from the discussion it also seems like there are valid reasons not to support dynamic requires

bnjm avatar Oct 19 '17 12:10 bnjm

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

ethantran avatar Dec 22 '17 05:12 ethantran

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

bnjm avatar Dec 27 '17 02:12 bnjm