wevm / wagmi

Reactive primitives for Ethereum apps
https://wagmi.sh
MIT License
5.88k stars 1k forks source link

Wagmi config #3469

Closed decapination-labs closed 7 months ago

decapination-labs commented 7 months ago

Describe the bug

import { createConfig, http } from 'wagmi';
import { mainnet, sepolia } from 'wagmi/chains';
import { coinbaseWallet, walletConnect } from 'wagmi/connectors';

export const config = createConfig({
  chains: [mainnet, sepolia],
  connectors: [
    walletConnect({
      projectId: process.env.NEXT_PUBLIC_W3C_PID,
    }),
    coinbaseWallet({ appName: 'DECAPINATION', darkMode: true }),
  ],
  transports: {
    [mainnet.id]: http(
      'https://eth-mainnet.g.alchemy.com/v2/StF61Ht3J9nXAojZX-b21LVt9l0qDL38',
    ),
    [sepolia.id]: http(
      'https://eth-sepolia.g.alchemy.com/v2/roJyEHxkj7XWg1T9wmYnxvktDodQrFAS',
    ),
  },
});

declare module 'wagmi' {
  interface Register {
    config: typeof config;
  }
}

This is my wagmi.ts file

I have a. nextjs14 app router application and i use pnpm .

all packages are up to date ( wagmi , viem , typescript.. )

I keep getting type error :

Type error: The inferred type of 'config' cannot be named without a reference to '.pnpm/viem@2.1.1_typescript@5.3.3_zod@3.22.4/node_modules/viem'. This is likely not portable. A type annotation is necessary.

Link to Minimal Reproducible Example

No response

Steps To Reproduce

No response

Wagmi Version

2.2.1

Viem Version

2.1.1

TypeScript Version

5.3.3

Check existing issues

Anything else?

No response

tmm commented 7 months ago

Works fine in this TypeScript Playground. Please add a minimal reproduction if you want us to re-open this issue.

decapination-labs commented 7 months ago

minimal reproduction:

pnpm create wagmi >> react >> next >> pnpm i

make sure u set declaration : true in ur tsconfig.ts

reason of adding declare : TSConfig Option

run pnpm build and u will get the error :

Type error: The inferred type of 'config' cannot be named without a reference to '.pnpm/viem@2.0.0_bufferutil@4.0.8_typescript@5.3.3_utf-8-validate@6.0.3/node_modules/viem'. This is likely not portable. A type annotation is necessary.
decapination-labs commented 7 months ago
import type { Config } from 'wagmi';
import { http, createConfig } from 'wagmi'
import { mainnet, sepolia } from 'wagmi/chains'
import { coinbaseWallet, injected, walletConnect } from 'wagmi/connectors'

export const config : Config = createConfig({
  chains: [mainnet, sepolia],
  connectors: [
    injected(),
    coinbaseWallet({ appName: 'Create Wagmi' }),
    walletConnect({ projectId: process.env.NEXT_PUBLIC_WC_PROJECT_ID ?? '123' }),
  ],
  ssr: true,
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

declare module 'wagmi' {
  interface Register {
    config: typeof config
  }
}

adding type Config for config removes the error while keeping declaration : true in tsconfig

any thoughts??

tmm commented 7 months ago

make sure u set declaration : true in ur tsconfig.ts

"declaration": true is set in this TypeScript Playground.

adding type Config for config removes the error

It may remove the error, but it widens the type of config to Config so Wagmi cannot infer anything useful.


Again, if you want me to look into this further, you need to attach a minimal reproduction. You can use this TypeScript Playground as a starting place.

decapination-labs commented 7 months ago

not sure how i can change the PM to pnpm and build

github-actions[bot] commented 7 months ago

This issue has been locked since it has been closed for more than 14 days.

If you found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest wagmi version. If you have any other comments you can create a new discussion.