question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript project fails to build; module 'web3/providers' not found

See original GitHub issue

As 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)

  1. Clone this project.
  2. Run yarn to install dependencies (of which ganache-core is one)
  3. Run yarn build to build the TypeScript source
  4. 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

7reactions
alcuadradocommented, Oct 31, 2019

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 a providers module.

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.ts in a post-install script, but that would only work for me, and not my users.

4reactions
bigspidercommented, Dec 17, 2019

Hi, is there any update on this issue? I’m having this problem as well.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found