Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing remote files via ES6 import

I have an ES6 React app thats being compiled and bundled via browserify.

I have several import statements like:

import React from 'react/addons'

I also need to use an external library that creates an HTML widget, hosted on a CDN. I've tried including the file before or after the bundle source:

<script src="//cdn.auth0.com/js/lock-7.9.min.js"></script>
<script type="text/javascript" src="scripts/build.js"></script>

When I try and reference the CDN provided object in the console, it works fine:

Auth0Lock
<-function Auth0Lock()...

Referencing it within the React app raises a syntax error. I assume I need to import it...but how?

like image 754
Allyl Isocyanate Avatar asked Oct 26 '15 19:10

Allyl Isocyanate


1 Answers

You can install auth0-lock via npm, and use it as a local dependency

npm install auth0-lock --save

and then import it to your app like this

import Auth0Lock from 'auth0-lock';
like image 197
Oleksandr T. Avatar answered Sep 28 '22 09:09

Oleksandr T.