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

Current "get around" require statement breaks #9

Open
dapplion opened this issue Apr 5, 2021 · 2 comments
Open

Current "get around" require statement breaks #9

dapplion opened this issue Apr 5, 2021 · 2 comments

Comments

@dapplion
Copy link

dapplion commented Apr 5, 2021

Running Lodestar on this branch ChainSafe/lodestar#2328 breaks with

TypeError: Class extends value undefined is not a constructor or null
    at Object.<anonymous> (/usr/app/node_modules/timeout-abort-controller/index.js:12:33)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/usr/app/node_modules/libp2p/src/dialer/index.js:9:27)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
/usr/app/node_modules/timeout-abort-controller/index.js:12
class TimeoutController extends AbortController {
                                ^

Seems that this detection does not cover some corner case

const { AbortController } =
typeof self !== 'undefined' ? self
: typeof window !== 'undefined' ? window
/* otherwise */ : require('abort-controller')

CC @wemeetagain

Example of error https://github.com/ChainSafe/lodestar/runs/2272944508?check_suite_focus=true#step:7:7

@dapplion
Copy link
Author

dapplion commented Apr 5, 2021

In a NodeJS environment self is defined and does not contain the AbortController property

{
  self: Object [global] {
    global: [Circular],
    clearInterval: [Function: clearInterval],
    clearTimeout: [Function: clearTimeout],
    setInterval: [Function: setInterval],
    setTimeout: [Function: setTimeout] {
      [Symbol(nodejs.util.promisify.custom)]: [Function]
    },
    queueMicrotask: [Function: queueMicrotask],
    clearImmediate: [Function: clearImmediate],
    setImmediate: [Function: setImmediate] {
      [Symbol(nodejs.util.promisify.custom)]: [Function]
    },
    self: [Circular]
  }
}

@wemeetagain
Copy link

The issue stems from the threads library attaching a global self object when its required.

Simple test case:

require('threads');
require('timeout-abort-controller');

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