Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with underscore.js #2282

Closed
filips123 opened this issue Jan 31, 2019 · 2 comments
Closed

Problems with underscore.js #2282

filips123 opened this issue Jan 31, 2019 · 2 comments

Comments

@filips123
Copy link
Contributor

Issue

I have code that uses web3. It should work in Node.js and browser so I use AEgir to build it for the browser (with Webpack).

It works normally in Node.js but there are problems in the browser.

When I include my built JS file, I get the error TypeError: root is undefined and none of my code works.

That error comes from underscore.js:

(function() {

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

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

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

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

The issue was already reported to jashkenas/underscore#2680, but they said that this is not a problem with underscore.js:

If you're transpiring 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 the underscore.

I don't know if this is an issue with Web3 or AEgir, so I first opened an issue here. Please let me know if this is an issue with AEgir so I will open an issue there.

Steps to reproduce

  1. Create project and install web3 and aegir.

  2. Create file src/index.js which uses web3:

'use strict'
const Web3 = require('web3')
  1. Build with aegir build.

  2. Create HTML file and include built script index.js.

  3. Open HTML file in browser and open developer console. You will see error.

Logs

Firefox:

TypeError: root is undefined[Več o tem] underscore.js:15
    Underscore 2
        <anonimno>
        <anonimno>
    Webpack 18
        __webpack_require__
        <anonimno>
        __webpack_require__
        <anonimno>
        __webpack_require__
        <anonimno>
        __webpack_require__
        <anonimno>
        <anonimno>
        __webpack_require__
        <anonimno>
        __webpack_require__
        <anonimno>
        __webpack_require__
        <anonimno>
        <anonimno>
        webpackUniversalModuleDefinition
        <anonimno>

Chrome:

Uncaught TypeError: Cannot read property '_' of undefined
    at underscore.js:15
    at Object.<anonymous> (underscore.js:1691)
    at __webpack_require__ (bootstrap:19)
    at Object.<anonymous> (index.js:27)
    at __webpack_require__ (bootstrap:19)
    at Object.<anonymous> (index.js:25)
    at __webpack_require__ (bootstrap:19)
    at Object.<anonymous> (index.js:32)
    at __webpack_require__ (bootstrap:19)
    at Object.<anonymous> (client.js:6)

Environment

  • Browser: Firefox and Chrome
  • Web3: beta 37
  • AEgir: 18.0.3
@nivida
Copy link
Contributor

nivida commented Jan 31, 2019

Since beta.38 does Web3.js use lodash and not underscore. Please upgrade to the latest version and it will solve your problem.

@nivida nivida closed this as completed Jan 31, 2019
@filips123
Copy link
Contributor Author

@nivida This is not possible because of problems with truffle-contract (see trufflesuite/truffle#1667). And I think that this worked in previous AEgir versions, so this is probably problem with it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants