Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

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

Closed
hrharder opened this issue Aug 16, 2019 · 16 comments
Closed

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

hrharder opened this issue Aug 16, 2019 · 16 comments

Comments

@hrharder
Copy link

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:
@hrharder
Copy link
Author

Alright I have found a solution. It appears these types refer to @types/web3 rather than the types provided by the web3 package.

I will close this issue, but I would suggest making the change I suggested, and removing the dependency on @types/web3, now that the web3 package includes TypeScript types by default.

@alcuadrado
Copy link
Contributor

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.

@bigspider
Copy link

bigspider commented Dec 17, 2019

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

@fabioberger
Copy link

Bump on this.

fabioberger added a commit to fabioberger/ganache-core that referenced this issue Jan 30, 2020
xianny added a commit to 0xProject/0x-monorepo that referenced this issue Jan 31, 2020
@alcuadrado
Copy link
Contributor

alcuadrado commented Feb 1, 2020

Hey @davidmurdoch @gnidan

I bumped into this issue once again, but this time I can't find a way to workaround it.

Have you considered just removing types from the package.json? TBH I think web3 should also do the same.

I know that removing the types can sound like a drastic measure, but I'm not sure who is actually using these typings, as they are broken. The only way to use ganache-core from a TS project is with require("ganache-core"), which ignores them. But you can't control if your dependencies use import or require.

I wouldn't delete the typings folder though, so if someone really wants to use those typings, they can do it by adding them to their tsconfig.json's files.

Thanks!

@alcuadrado
Copy link
Contributor

I'm not sure who is actually using these typings, as they are broken

I just realized that they are only broken if you also have a web3 installation. So maybe that's why not everyone is complaining about this.

@alcuadrado
Copy link
Contributor

Update: I found a workaround. If I don't install web3 and install @types/web3@1.0.19 I can compile my project.

@fabioberger this may help you

@feuGeneA
Copy link

feuGeneA commented Apr 6, 2020

I too am hitting this problem. Suggested workaround (from @alcuadrado ) doesn't work for me because I also depend on web3. This is the hack I've put in place to unblock myself:

package.json

{
    "scripts": {
        "install": "sed -ie 's!import { Provider as Web3Provider } from \"web3/providers\";!import { Web3EthereumProvider as Web3Provider } from \"web3-providers\";!' node_modules/ganache-core/typings/index.d.ts"
    }
}

feuGeneA added a commit to 0xProject/0x-api that referenced this issue Apr 7, 2020
feuGeneA added a commit to 0xProject/0x-api that referenced this issue Apr 7, 2020
feuGeneA added a commit to 0xProject/0x-api that referenced this issue Apr 7, 2020
feuGeneA added a commit to 0xProject/0x-api that referenced this issue Apr 7, 2020
feuGeneA added a commit to 0xProject/0x-api that referenced this issue Apr 7, 2020
feuGeneA added a commit to 0xProject/0x-api that referenced this issue Apr 7, 2020
feuGeneA added a commit to 0xProject/0x-api that referenced this issue Apr 7, 2020
feuGeneA added a commit to 0xProject/0x-api that referenced this issue Apr 10, 2020
feuGeneA added a commit to 0xProject/0x-api that referenced this issue Apr 10, 2020
feuGeneA added a commit to 0xProject/0x-api that referenced this issue Apr 10, 2020
feuGeneA added a commit to 0xProject/0x-api that referenced this issue Apr 10, 2020
feuGeneA added a commit to 0xProject/0x-api that referenced this issue Apr 11, 2020
feuGeneA added a commit to 0xProject/0x-api that referenced this issue Apr 11, 2020
@feuGeneA
Copy link

Any update on this? This has become a notorious issue that several people on my team have independently run into, with no known workaround better than my brutish hack.

feuGeneA added a commit to 0xProject/0x-api that referenced this issue Apr 16, 2020
* test: Stop running contract migrations

They're already deployed in the snapshot.  No need to deploy them
again.

* Add test of /swap/v0/quote endpoint

* Add and use RFQ-T configuration types

* yarn clean: separate docker from ts

* Only run prettier on ./src

To avoid trying to descend into docker-created folders, which are
root-access-only when running in a Linux environment.

* yarn add --dev make-promises-safe

Because it's used (in the mocha invocation) and wasn't present after
`yarn install`.

* Include prettier in lint

* Adapt to new RFQ-T namespace in SwapQuoterOpts

* Adapt to new RFQ-T namespace in SwapQuoterReqOpts

* Revert addition of env var defs to `yarn dev`

Addresses review comment #162 (comment)

* Don't enforce presence of taker address

Just pass the API key through to the maker.

Addresses review comment #162 (comment)

* Enforce a specific value for intentOnFilling

Addresses review comment #162 (comment)

* Remove unused apiKey parameter

Addresses review comment #162 (comment)

* Add `rfqt:` namespace for RFQ-T specific options

Addresses review comment #162 (comment)

* Parse RFQT environment variables as CSV, not JSON

Addresses review comment #162 (comment)

* Set RFQT taker address to Forwarder for ETH sales

Addresses review comment #162 (comment)

* Restore accidentally deleted line in recent commit.

Restoring a line that was accidentally deleted in 2578a79

Addresses review comment 2578a79#r406599327

* Add metadata for dummy kovan tokens

* introduce new test using rfqtMocker

* TEMPORARY: use gene's ganache snapshot for tests

* HACK: fix ganache-core bug

See open issue at
trufflesuite/ganache#465 (comment)

* TEMPORARY: Update gitpkg monorepo references

* Enable prettier for {.,test}/**/*.{ts,tsx,json,md}

Addresses review comment #162 (comment)

* Add SwapQuoteRequestParam `skipValidation`

Addresses review comments
#162 (comment)
and
#162 (comment)

* Add API Key and `intentOnFilling` to API schema

* Parse present but empty intentOnFilling as true

* Fix bug: env var csv split was wrongly applied

Addresses review comments
#162 (comment)
and
#162 (comment)

* RFQT: More tests (#170)

* generate source maps

* abstract tests out into nested contexts

* test for skipping validation

* dont include order for maker who does not have allowances set

* bad api key test

* fix test names and explicitly deposit so taker can fill

* Validate bool query params as enum, not presence

Addresses the following review comments:
- #162 (comment)
- #162 (comment)
- #162 (comment)

* Add comments around using Forwarder as Taker

Addresses review comment #162 (comment)

* Test no quote provided when taker address absent

* Revert "TEMPORARY: Update gitpkg monorepo references"

This reverts commit 08f4d31.

* Revert "TEMPORARY: use gene's ganache snapshot for tests"

This reverts commit 7c448d3.

* Pin updated monorepo deps to development revision

Pin to a gitpkg publish of the monorepo dependencies changed to support
this PR to a commit hash of the development branch, rather than that of
my PR branch.

* Pin tests' ganache snapshot to monorepo commit

I published a custom ganache image, with a monorepo commit hash appended
to the version number for reference.

* Simplify expressions parsing boolean query params

Co-authored-by: Steve Klebanoff <steve@0xproject.com>
@sushrest
Copy link

This worked for me

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 * as Web3Provider from "web3";

  namespace Ganache {
    export interface IProviderOptions {
// ...

@davidmurdoch
Copy link
Member

davidmurdoch commented Apr 18, 2020

Hey all, if you've fixed this please feel free to open a PR and I'll merge it in ASAP! I'll be able to work through the backlog of issues very soon!

Edit: looks like I've already got a PR here: #547 I'll see if I can get this in the next update. Sorry for the long wait on this!

sushrest added a commit to sushrest/ganache-core that referenced this issue Apr 19, 2020
@sushrest
Copy link

Hey all, if you've fixed this please feel free to open a PR and I'll merge it in ASAP! I'll be able to work through the backlog of issues very soon!

Edit: looks like I've already got a PR here: #547 I'll see if I can get this in the next update. Sorry for the long wait on this!

@davidmurdoch the PR #547 still outputs following error:
node_modules/ganache-core/typings/index.d.ts(3,12): error TS2305: Module '"web3"' has no exported member 'Provider'.

The fix was importing as import * as Web3Provider from "web3";

I have a PR #567 with the fix.

@adrianmcli
Copy link
Contributor

adrianmcli commented Apr 19, 2020

I had this same error too, but I fixed it by limiting my project's tsconfig to only compile things in my src folder and it went away.

Maybe my bug is not the same as you guys, but I figured someone might google this and want to try this out.

// tsconfig.json
{
  "include" :["src/**/*.ts"],
  "compilerOptions": {
    ...
  }
}

@MoMannn
Copy link

MoMannn commented May 4, 2020

+1

@tcoulter
Copy link
Contributor

Just ran into this issue as well. Installing ganache@beta fixed this for me.

@davidmurdoch
Copy link
Member

Closing, fixed by 2f81da2

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests