I am trying to rewrite an old application that uses require.js to use es6 import. One of the libraries used is Backbone and Underscore. To create one large package and pre-build es6 on es5, I use Webpack with the babel loader. The bundle is created, but when I load it in the browser, I get the following error:
Uncaught TypeError: Cannot read property '_' of undefined
It seems that 'this' in Underscore is undefined in the created .js package, so root._ gives me an error.
// Baseline setup // -------------- // Establish the root object, `window` in the browser, or `global` on the server. var root = this; // Save the previous value of the `_` variable. var previousUnderscore = root._; // Establish the object that gets returned to break out of a loop iteration. var breaker = {}
Has anyone experienced the same issue?
source share