archilogic-com / 3dio-js

JavaScript toolkit for interior apps

Home Page:https://3d.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

bnjm opened this issue · 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 ( 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

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

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