Underscore: Uncaught TypeError: Cannot read property '_' of undefined

Created on 17 Jun 2017  路  2Comments  路  Source: jashkenas/underscore

When I try to import the library into my ReactJS app, I get this error:

underscore.js:15 Uncaught TypeError: Cannot read property '_' of undefined

The error is thrown here. root is undefined.

(function() {

  // Baseline setup
  // --------------

  // Establish the root object, `window` in the browser, or `exports` on the server.
  var root = this;

  // Save the previous value of the `_` variable.
  var previousUnderscore = root._; // <==  !!! HERE !!!

  // Save bytes in the minified (but not gzipped) version:
  var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;

Why does it happen? How to solve?

question

All 2 comments

If you're transpiling with babel, or using "use strict", the value of this will always be set to undefined, which is why root is undefined. You need to do this differently. This is not a problem with underscore.

@bjmiller I have the same problem. I am using AEgir to build my project for the browser (with Webpack). This project is required by Web3 and it causes the error. How can I fix this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jdalton picture jdalton  路  4Comments

jdalton picture jdalton  路  6Comments

marcalj picture marcalj  路  5Comments

markvr picture markvr  路  3Comments

Francefire picture Francefire  路  5Comments