wagmi: bug: using `@wagmi/cli` in a pnpm monorepo, TS4058 | TS2742

Is there an existing issue for this?

  • I have searched the existing issues

Package Version

0.1.6

Current Behavior

I want to use the @wagmi/cli generated hooks inside a pnpm turborepo and reuse it across external projects.


Attempts:

I have two possible ways to achieve that:

  1. Export the generated.ts file in the package.json: main (i have a typescript project);
  2. Compile the generated.ts with tsc and tsconfig.json: declaration: true to generate both typings and the js file.

1. Exporting generated.ts itself:

The package compiles, but when is used in another repo, the TS2742 issue appears:

../../node_modules/.pnpm/does-not-matter-sdk@1.4.0_nqqoae3ectxrvfzrr4j442idbu/node_modules/does-not-matter/contracts-sdk/sdk/generated.ts:9179:17
Type error: The inferred type of 'useAccessControl' cannot be named without a reference to '.pnpm/@ethersproject+contracts@5.7.0/node_modules/@ethersproject/contracts'. This is likely not portable. A type annotation is necessary.

In the wagmi repository itself, I’ve seen the next type configuration: https://github.com/wagmi-dev/wagmi/blob/0b8523e2bb0fee172b53fbf14b9b399630aa442e/tsconfig.json#L36-L42

I bet this was also an issue for wagmi monorepo too, but type inferring has successfully been fixed by those lines, as when I delete them locally, the same TS2742 is thrown.

Maybe @ethersproject/contracts is also worth adding to the list?

2. Compiling generated.ts and exporting generated.d.ts, generated.js:

The package does not compile, throwing the next error:

sdk/generated.ts:28532:17 - error TS4058: Return type of exported function has or is using name 'EventListener' from external module "/does-not-matter/contracts/node_modules/@wagmi/core/dist/index" but cannot be named.

Honestly no idea about this one.

Expected Behavior

So, I would like to export the generated file into a dedicated NPM package, and I expect the typings to be inferred correctly in my project.

Steps To Reproduce

  1. Clone the repo https://github.com/h0tw4t3r/wagmi-cli-issue, which is based on top of create-wagmi:next-cli-foundry
  2. yarn install
  3. yarn pkg:build

Link to Minimal Reproducible Example (StackBlitz, CodeSandbox, GitHub repo etc.)

https://github.com/h0tw4t3r/wagmi-cli-issue

Anything else?

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 23 (20 by maintainers)

Most upvoted comments

Hi there! Sorry you are running into these issues. As they are specific to your TypeScript set up and not unique to wagmi, I’m going to close this issue. I recommend searching around the TypeScript repo to see if you can find something to help out there (e.g. https://github.com/microsoft/TypeScript/issues/42873). Good luck!

When i said pr to wagmi I meant literally doing a pr to wagmi to fix the issue in wagmi not in your code.

I heard 3 months or so for 1.0.0. I don’t speak for wagmi but I would expect something like this to not be prioritized in meantime but I’m sure they would accept a pr

The issue can be fixed by doing a pr to wagmi to export the types. It will likely fix itself once wagmi upgrades to 1.0.0. Worth noting the issue is actually wagmi and not the wagmi cli.

hey @h0tw4t3r,

I looked at this briefly and noticed a 2 things

  1. This is a yarn repo not a pnpm repo. There is also a package-lock.json in this repo too. You will need to completely clean your node modules and delete some lock files to rebuild clean
  2. Your repo is failing because of your tsconfig setup and not because of the wagmi cli

Your repo builds fine for me image

I hope this helps. Try getting rid of your tsconfig changes and building the tsconfig up from a clean config.