-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Can't import Web3 v4.x in typescript #5907
Comments
Hi @Loque18, thanks for reaching out Have you tried setting |
I found out something, if I do eslint stops linting but then new errors show up in the console
|
I may have been mistaken with the below response. @luu-alex mentioned that this could be the result of not specifying Hi @Loque18, apologies for the late reply, but these In your resolve: {
extensions: ['.ts', '.js'],
fallback: {
fs: false,
net: false,
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('readable-stream'),
},
} And as
This might not completely resolve all the errors you're facing, so if you're still having troubles, please share the repo you're trying to install Lastly, using |
Hi @spacesailor24 and thanks for answering this issue, Sorry for the late reply, I updated the version to @4.0.1-rc.0, the error is no longer being marked by vscode, shamefully there are a some errors on the console, these are the errors, looks like they are related to the way they are imported in some part of the core code I guess, all of them are of type Error: node_modules/ethereumjs-util/dist/externals.d.ts:6:8 - error TS1259: Module '"C:/Users/DELL/Documents/orcania/cel-w3/node_modules/@types/bn.js/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag
6 import BN from 'bn.js';
~~
node_modules/@types/bn.js/index.d.ts:598:1
598 export = BN;
~~~~~~~~~~~~
This module is declared with 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
Error: node_modules/rlp/dist/types.d.ts:2:8 - error TS1259: Module '"C:/Users/DELL/Documents/orcania/cel-w3/node_modules/@types/bn.js/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag
2 import BN from 'bn.js';
~~
node_modules/@types/bn.js/index.d.ts:598:1
598 export = BN;
~~~~~~~~~~~~
This module is declared with 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
Error: node_modules/web3-providers-ws/lib/index.d.ts:4:8 - error TS1259: Module '"C:/Users/DELL/Documents/orcania/cel-w3/node_modules/isomorphic-ws/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag
4 import WebSocket, { ClientOptions, CloseEvent } from 'isomorphic-ws';
~~~~~~~~~
node_modules/isomorphic-ws/index.d.ts:8:1
8 export = WebSocket
~~~~~~~~~~~~~~~~~~
This module is declared with 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag. I created a repo repo so that you can check the issues by yourself, regarding the last part thanks for your help by the way :) ! |
Is there an existing issue for this?
Current Behavior
I created a new angular project and installed
[email protected]
, I tried importing it usingand this errors showed up
Expected Behavior
to be allowed to import web 3 like this
import { Web3 } from 'web3';
Steps to Reproduce
ng new app
npm i [email protected]
paste the following code in app.component.ts
Web3.js Version
4.0.1-alpha.5
Environment
Anything Else?
No response
The text was updated successfully, but these errors were encountered: