This repository was archived by the owner on Mar 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
Import Web3 not working in Typescript #2363
Copy link
Copy link
Closed
Labels
BugAddressing a bugAddressing a bug
Description
Expected behavior
Documentation should accurately describe the way to import Web3 into a Typescript project. There are conflicting documentations about the correct import, neither of which work.
https://github.com/ethereum/web3.js#usage-with-typescript
import Web3 from 'web3';
const web3 = new Web3("ws://localhost:8546");
https://web3js.readthedocs.io/en/1.0/web3.html
import {Web3} from 'web3';
// "Web3.providers.givenProvider" will be set if in an Ethereum supported browser.
const web3 = new Web3(Web3.givenProvider || 'ws://some.local-or-remote.node:8546');
Actual behavior
Errors from both approaches, see below for logs.
Steps to reproduce the behavior
- Create Typescript project.
- Import using either of the documented processes.
Error Logs
[1] const web3 = new web3_1.Web3("ws://localhost:8546");
[1] ^
[1]
[1] TypeError: web3_1.Web3 is not a constructor
[1] at Object.<anonymous> (/Users/rahul/Desktop/connext/connext/moloch-monorepo/packages/moloch-backend/dist/src/index.js:6:14)
[1] at Module._compile (internal/modules/cjs/loader.js:734:30)
[1] at Object.Module._extensions..js (internal/modules/cjs/loader.js:745:10)
[1] at Module.load (internal/modules/cjs/loader.js:626:32)
[1] at tryModuleLoad (internal/modules/cjs/loader.js:566:12)
[1] at Function.Module._load (internal/modules/cjs/loader.js:558:3)
[1] at Module.require (internal/modules/cjs/loader.js:663:17)
[1] at require (internal/modules/cjs/helpers.js:20:18)
[1] at Object.<anonymous> (/Users/rahul/Desktop/connext/connext/moloch-monorepo/packages/moloch-backend/dist/index.js:6:10)
[1] at Module._compile (internal/modules/cjs/loader.js:734:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:745:10)
[1] at Module.load (internal/modules/cjs/loader.js:626:32)
[1] at tryModuleLoad (internal/modules/cjs/loader.js:566:12)
[1] at Function.Module._load (internal/modules/cjs/loader.js:558:3)
[1] at Module.require (internal/modules/cjs/loader.js:663:17)
[1] at require (internal/modules/cjs/helpers.js:20:18)
Versions
Web3.js: 1.0.0-beta.46
Node: v11.9.0
NPM: v6.5.0
Metadata
Metadata
Assignees
Labels
BugAddressing a bugAddressing a bug