Loredra L
Loredra L

Reputation: 1553

How to use ES6-symbol polyfill

I have an Symbol is not defined in IE so I tried to use this library as polyfill

https://github.com/medikoo/es6-symbol

As inexperienced as I am, I do not really know how to include it so that it use as global. In detail, in my code I include it using requirejs as:

requirejs.config({
    paths: 
     {  'symbol': 'libs/es6-symbol/index'    }
 })

//define it in app entry point

require([
    'symbol'],
 function (sy) {
             //What should I do?
              }

How should i approach this?

Upvotes: 2

Views: 5033

Answers (1)

Louis
Louis

Reputation: 151380

You cannot just load the index.js of es6-symbol with RequireJS. If you just look at it, you'll see:

'use strict';

module.exports = require('./is-implemented')() ? Symbol : require('./polyfill');

This is valid CommonJS code but not valid AMD code. RequireJS supports AMD natively, not CommonJS. To use CommonJS code with RequireJS you'd have at a minimum to wrap the code above in a define call, which means having a build step.

Ultimately, you should heed the advice of the README:

To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: Browserify, Webmake or Webpack

Research the bundlers, pick one, write a build configuration for it, and if you still have trouble you can ask on this site.

Upvotes: 4

Related Questions