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

TypeError: #<Object> is not a constructor with Typescript and lerna bootstrap --ci #11

Closed
kuzdogan opened this issue Nov 30, 2021 · 1 comment

Comments

@kuzdogan
Copy link

I was trying to make use of Promise.any in a Typescript package and I came across the above error. Interestingly it is failing only on our circleci/node:14 build but works fine on all local node builds.

I was able to find a workaround so posting this here for rather documentation purposes than a bug report.

This is where the call is being made:

import promiseAny from  'promise.any';
...
...
const rpcPromises: Promise<string>[] = [];
for (const web3 of web3array) {
    rpcPromises.push(web3.eth.getCode(address));
    console.log(web3.currentProvider);
}
try {
    // Promise.any for Node v15.0.0<
    console.log(rpcPromises)
    return promiseAny([ 
        ...rpcPromises,
        new Promise((_resolve, reject) => {
            setTimeout(() => reject('RPC took too long to respond'), 3e3);
        })
    ])
} catch (err: any) {
    console.log(err)
    throw new Error(err);
}

and I get the following Error output:

ethereum-sourcify: TypeError: #<Object> is not a constructor
ethereum-sourcify:     at Object.resolve (<anonymous>)
ethereum-sourcify:     at PromiseResolve (/home/circleci/source-verify/services/verification/node_modules/es-abstract/2020/PromiseResolve.js:15:9)
ethereum-sourcify:     at /home/circleci/source-verify/services/verification/node_modules/promise.any/implementation.js:31:21
ethereum-sourcify:     at Array.map (<anonymous>)
ethereum-sourcify:     at map (/home/circleci/source-verify/services/verification/node_modules/array.prototype.map/index.js:17:18)
ethereum-sourcify:     at Object.any (/home/circleci/source-verify/services/verification/node_modules/promise.any/implementation.js:30:16)
ethereum-sourcify:     at Object.any [as default] (/home/circleci/source-verify/services/verification/node_modules/promise.any/index.js:16:9)
ethereum-sourcify:     at Object.getBytecode (/home/circleci/source-verify/services/verification/build/utils.js:68:37)
ethereum-sourcify:     at Injector.matchBytecodeToAddress (/home/circleci/source-verify/services/verification/build/services/Injector.js:120:50)
ethereum-sourcify:     at Injector.inject (/home/circleci/source-verify/services/verification/build/services/Injector.js:346:32)
ethereum-sourcify:     at runMicrotasks (<anonymous>)
ethereum-sourcify:     at processTicksAndRejections (internal/process/task_queues.js:95:5)

The bug happened at the commit ethereum/sourcify@4265f6b when running the tests on circleci.

Reproduce

To reproduce clone the repo and checkout the commit ethereum/sourcify@4265f6b.

git clone https://github.com/ethereum/sourcify.git && cd sourcify && git checkout 4265f6b2d219bed10e08ab76f7912e413f5c9e1f

Install dependencies with lerna. Here the difference with CircleCI and the local builds is that CircleCI installs with a --ci flag. I can only reproduce with the --ci flag

npx lerna bootsrap --ci

Run the tests

npm run test

If you install without the --ci flag the tests will all pass.

Fix

Following this comment in this issue, I was able to fix the problem es-shims/Promise.allSettled#5 (comment)

// import promiseAny from  'promise.any';
import promiseAny = require('promise.any');
@ljharb
Copy link
Member

ljharb commented Nov 30, 2021

This is a known issue with TypeScript; es-shims/Promise.allSettled#5 indeed describes it.

I'd strongly suggest using babel, not tsc, to transpile your TypeScript - for many reasons - which would avoid having to use the nonstandard import = require syntax.

I'll close this, because this package is correct by spec, and there's nothing we can do until TS fixes its transpilation bug.

@ljharb ljharb closed this as completed Nov 30, 2021
kuzdogan added a commit to ethereum/sourcify that referenced this issue Nov 30, 2021
The tests were failing because of an unknown issue with the Promise.any
shim package used. Tests were working locally because locally `npx lerna
bootstrap` was being used but CircleCI uses `npx lerna bootstrap --ci`.
Changes fix the error and tests pass.

The issue is documented here:
es-shims/Promise.any#11
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