Reputation: 6973
I am working with Polymer 1.0 and now it's time to add an external .JS library.
The library I want to add is called SuperAgent and it is a Node.js module capable to provide powerful APIs for XMLHttpRequests. It is also suggested by Polymer's team.
Step 01 - Add bower module
$ bower install --save superagent
Step 02 - Add <script>
reference
<!-- SuperAgent -->
<script
type="text/javascript"
src="/bower_components/superagent/lib/client.js"></script>
Now I get an error in Chrome saying:
Uncaught ReferenceError: require is not defined
If I inspect the client.js file, it has these statements at the beginning, which are the cause of my error:
/**
* Module dependencies.
*/
var Emitter = require('emitter');
var reduce = require('reduce');
Now, my project is done using exclusively bower, what do I need to do in order to make "require" understandable by my Polymer app? Is there a bower component + script that do that?
Upvotes: 0
Views: 536
Reputation: 56966
I have used SuperAgent before and I am familiar with Polymer (but haven't used it much)
SuperAgent is a server side nodeJS npm package used to stand up a server for running a batch of unit tests and it is then shut down.
Polymer is a client side tool used to make the full power of the shadow DOM available now.
How the 2 work together I have no idea but the require statements used by SuperAgent are nodeJS require statements made to require other modules. The reason your browser doesn't understand require is because browsers don't yet understand modularity (although they will do soon with ES6 modules on the way in).
Upvotes: 1