TypeScript project fails to build; module 'web3/providers' not found
See original GitHub issueAs of a few days ago, a TypeScript project I am working on suddenly started failing, reporting an issue originating from node_modules/ganache-core/typings/index.d.ts (see full error below).
The issue appears to be the typings/index.d.ts file imports some types from package web3/providers, which really should just be web. This PR addresses that. I was able to confirm the change solves my problem
Expected Behavior
The project should build with no error.
Current Behavior
The project fails to build with tsc with the following error:
$ tsc
node_modules/ganache-core/typings/index.d.ts:2:44 - error TS2307: Cannot find module 'web3/providers'.
2 import { Provider as Web3Provider } from "web3/providers";
~~~~~~~~~~~~~~~~
Found 1 error.
Possible Solution
Before
// from typings/index.d.ts
declare module "ganache-core" {
import { Provider as Web3Provider } from "web3/providers";
namespace Ganache {
export interface IProviderOptions {
// ...
After
// from typings/index.d.ts
declare module "ganache-core" {
import { Provider as Web3Provider } from "web3";
namespace Ganache {
export interface IProviderOptions {
// ...
Steps to Reproduce (for bugs)
- Clone this project.
- Run
yarnto install dependencies (of whichganache-coreis one) - Run
yarn buildto build the TypeScript source - See the error above
Context
Our project fails to build locally and in CI environments, prohibiting us from continuing to integrate changes into our codebase.
Your Environment
- Version used:
2.7.0 - Environment name and version:
- Node.js LTS (10.15.3)
- TypeScript (
3.5.3) - Yarn (
1.17.3)
- Operating System and version:
- MacOS (darwin)
- Linux
- Link to your project:
- Private project
- This project isolates the issue.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:16 (8 by maintainers)
Top Results From Across the Web
Angular + web3.js: Module not found: Error: Can't resolve 'crypto'
The easist way to make it working is to patch webpack.config.js generated by Angular CLI.
Read more >How to Use Web3React in Your Next Project - Linum Labs
The idea is that you need to import a provider (generally via Ethers or Web3.js in the JavaScript/TypeScript space), and then instantiate and...
Read more >web3-providers-http - npm
Module to handle web3 RPC connections over HTTP. ... Start using web3-providers-http in your project by running `npm i web3-providers-http`.
Read more >How to use web3.js@1.0.0-beta34 with TypeScript?
ts(2,21): error TS7016: Could not find a declaration file for module 'underscore'. '/Users/maxblock/node_modules/underscore/underscore.js' ...
Read more >module not found: error: can't resolve 'assert' in - You.com
I think that because your create react app (CRA) does not recognize your webpack.config.js . Your setting for polyfills is correct. Setting up...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hey @davidmurdoch
This issue reappeared with the latest release of
web3, as it now has TS types again.web3’s built-in types win over@types/web3, and they don’t have aprovidersmodule.This is preventing me from compiling one of my projects, and I couldn’t find a workaround so far. I think I could delete
typings/index.d.tsin a post-install script, but that would only work for me, and not my users.Hi, is there any update on this issue? I’m having this problem as well.