truffle
truffle copied to clipboard
Broken TypeScript typings on fresh install
- [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
-
npm install @truffle/hdwallet-provider web3
- Put inside
src/index.ts
:
import HDWalletProvider from "@truffle/hdwallet-provider";
console.log("Hello world!")
-
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
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 looks like this may be related to npm 7
, which comes with node 15 by default
@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
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"
Hi @cds-amal I've got both and no luck, can you confirm you tested?
Hey @Butterneck that is weird. What is the error? Here's the text cast of my test
@cds-amal, thx, it resolves the problem.
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]
This is fixed and released in v5.4.23
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.
Thanks for the report @ali-bahjati. I confirmed the broken behavior.
Same issue
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.
This should be fixed in v5.6.9.