truffle icon indicating copy to clipboard operation
truffle copied to clipboard

Broken TypeScript typings on fresh install

Open Butterneck opened this issue 3 years ago • 12 comments

  • [x] I've asked for help in the Truffle Gitter before filing this issue.

Issue

After a fresh install of @truffle/hdwallet-provider (other packages possibly affected as well) TypeScript typings are not working correctly and compilation fails.

Steps to Reproduce

  1. npm install @truffle/hdwallet-provider web3
  2. Put inside src/index.ts:
import HDWalletProvider from "@truffle/hdwallet-provider";
console.log("Hello world!")
  1. npx typescript --esModuleInterop src/index.ts

Expected Behavior

Compilation succeeds without any issues.

Actual Results

Typecheck fails with the following errors:

node_modules/@truffle/hdwallet-provider/dist/index.d.ts:2:61 - error TS2307: Cannot find module 'ethereum-protocol'.
import { JSONRPCRequestPayload, JSONRPCErrorCallback } from "ethereum-protocol";
                                                             ~~~~~~~~~~~~~~~~~~~
node_modules/@truffle/hdwallet-provider/dist/index.d.ts:3:43 - error TS2307: Cannot find module 'web3/providers'.
import { Callback, JsonRPCResponse } from "web3/providers";
                                           ~~~~~~~~~~~~~~~~

Environment

  • Operating System: Tested on Arch Linux
  • Ethereum client:
  • Truffle version (truffle version): Truffle v5.1.65 (core: 5.1.65) Solidity v0.5.16 (solc-js) Node v15.7.0 Web3.js v1.2.9
  • node version (node --version): v15.7.0
  • npm version (npm --version): 7.4.3

Butterneck avatar Feb 07 '21 16:02 Butterneck

Yikes! We'll have to look into this. Hopefully this is as simple as adding skipLibCheck to hdwallet-provider's tsconfig.

Thanks for reporting!

gnidan avatar Feb 24 '21 19:02 gnidan

@gnidan looks like this may be related to npm 7, which comes with node 15 by default

cds-amal avatar Jun 15 '21 01:06 cds-amal

@gnidan looks like this may be related to npm 7, which comes with node 15 by default

Same problem with NPM 6 and node 14.16.0 here

zen0dev avatar Jun 30 '21 23:06 zen0dev

Hi @binzydev,

We might have to move some types from devDependencies to dependencies so that they make it to the declarations file. As a workaround you can manually install them.

yarn add -D @types/web3@"1.0.20" @types/ethereum-protocol@"^1.0.0"  

cds-amal avatar Jul 01 '21 00:07 cds-amal

Hi @cds-amal I've got both and no luck, can you confirm you tested?

zen0dev avatar Jul 01 '21 07:07 zen0dev

Hey @Butterneck that is weird. What is the error? Here's the text cast of my test

cds-amal avatar Jul 01 '21 09:07 cds-amal

@cds-amal, thx, it resolves the problem.

notnATrue avatar Jul 01 '21 11:07 notnATrue

Hi @cds-amal I've got both and no luck, can you confirm you tested?

Hello @Butterneck , some release of @types/web3 after 1.0.20 and 1.2.2 stubbed out the definition files and broke type declarations. Can you try pinning the version to 1.0.20? You can do that with

npm install @types/[email protected]

cds-amal avatar Jul 02 '21 16:07 cds-amal

This is fixed and released in v5.4.23

lsqproduction avatar Dec 02 '21 23:12 lsqproduction

I am still facing the problem with the latest version of wallet provider. To solve I needed to manually install "@types/web3-provider-engine" "@types/ethereum-protocol" and lock "@types/web3" to the version mentioned above.

So I'm not sure the issue have actually been resolved.

ali-bahjati avatar May 16 '22 17:05 ali-bahjati

Thanks for the report @ali-bahjati. I confirmed the broken behavior.

cds-amal avatar May 17 '22 03:05 cds-amal

Same issue

arjunpat avatar Jul 22 '22 04:07 arjunpat

Yikes! We'll have to look into this. Hopefully this is as simple as adding skipLibCheck to hdwallet-provider's tsconfig.

So it turns out this won't affect the distributed package. I tried this and manually included it in a test project. However, there is nothing in there that would affect things at compilation-time it seems.

eggplantzzz avatar Sep 27 '22 18:09 eggplantzzz

This should be fixed in v5.6.9.

sukanyaparashar avatar Dec 08 '22 23:12 sukanyaparashar