implementing with react-vr: npm vs cdn
opened this issue · comments
Description:
When installing webvr-polyfill through npm and implementing as shown below, I receive the following error when bundling:
error: bundling failed: "TransformError: /ExampleVR/node_modules/webvr-polyfill/build/webvr-polyfill.js: Couldn't find preset "env" relative to directory "/ExampleVR/node_modules/webvr-polyfill""
import WebVRPolyfill from 'webvr-polyfill';
import '../process';
import { VRInstance } from 'react-vr-web';
const polyfill = new WebVRPolyfill();
function init(bundle, parent, options) {
...
}
When I comment out the npm import and supply via CDN <script src='https://cdn.jsdelivr.net/npm/webvr-polyfill@latest/build/webvr-polyfill.js'></script>
however, this error does not occur and everything bundles correctly as expected.
Additional Information:
- webvr-polyfill version: ^0.10.2
- Browser name/version/release channel: Google Chrome Version 63.0.3239.84 (Official Build) (64-bit)
- Operating System: macOS High Sierra Version 10.13.2
A quick guess, but I think whatever build system you're using is attempting to apply a transformation to the dependency, finding webvr-polyfill's .babelrc (babel-preset-env) and failing since it does not have that (nor is it necessary). I think ignoring the node_modules directory in your babel configuration should fix this. Let me know!
That sounds like a good guess, but haven't been able to test it out. React-vr uses react native for the build system, so the babel config is hidden somewhere in the native source files and I haven't been able to find the right place to apply the ignore. This project was set up using the react-vr cli, so I'm a little surprised this hasn't been documented until now.
Interesting, I'll dig into react-vr some more and see how that works. In the mean time, I think you should be able to remove the .babelrc
in the webvr-polyfill directory, that way if it is getting built for React VR, it won't do anymore transformations (nor plugin failures)
Bingo! Removed the .babelrc
from webvr-polyfill and everything works as expected. Thanks for all of your help, it's greatly appreciated! It's pretty clear now that this is more of an issue with react-vr (and by extension, react-native's) build getting confused than anything webvr-polyfill is doing... so perhaps I opened this issue on the wrong repo. Regardless, let me know if you find out anything else worth sharing!
Created #305, should be fixed after next update