Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoimport Nuxt eventemitter3 does not provide an export named 'default' #3977

Open
1 task done
reslear opened this issue May 23, 2024 · 9 comments
Open
1 task done
Labels
Good First Issue Misc: Good First Issue

Comments

@reslear
Copy link

reslear commented May 23, 2024

Describe the bug

If you delete imports, Nuxt auto-imports do not work:

for example works:

<script setup lang="ts">
import { useAccount, useDisconnect } from '@wagmi/vue';

const { address, chainId, status } = useAccount();
const { disconnect } = useDisconnect();
</script>

not working:

<script setup lang="ts">
const { address, chainId, status } = useAccount();
const { disconnect } = useDisconnect();
</script>
Screenshot 2024-05-23 at 16 06 16
Uncaught SyntaxError: The requested module '/_nuxt/node_modules/.pnpm/[email protected]/node_modules/eventemitter3/index.js?v=2c858a2b' 
does not provide an export named 'default' (at index.mjs:1:8)

Link to Minimal Reproducible Example

https://stackblitz.com/~/github.com/reslear/nuxt-wagmi-starter

Steps To Reproduce

stackblitz also not working because metask sdk issues.

  1. clone repo github.com/reslear/nuxt-wagmi-starter

  2. install and run dev:

pnpm install
pnpm dev
  1. go to components/Account.vue and comment import line:
Screenshot 2024-05-23 at 16 09 31
  1. see result

Wagmi Version

latest

Viem Version

latest

TypeScript Version

latest

Check existing issues

Anything else?

No response

@tmm tmm added the Good First Issue Misc: Good First Issue label May 23, 2024
@Utilitycoder
Copy link

I would like to work on this issue and contribute the necessary changes.

@reslear
Copy link
Author

reslear commented May 29, 2024

maybe @danielroe can take a quick professional look and help?

https://github.com/wevm/wagmi/blob/main/packages/vue/src/nuxt/module.ts

@danielroe
Copy link

This is likely because without the explicit import, vite doesn't know to optimize the dep. You can manually add it to optimize-deps: https://vitejs.dev/config/dep-optimization-options.html#optimizedeps-include.

@reslear
Copy link
Author

reslear commented May 30, 2024

like ?

      nuxt.hook('vite:extendConfig', (config) => {
        config.optimizeDeps ??= {}
        config.optimizeDeps.include = config.optimizeDeps.include || []
        config.optimizeDeps.include.push('@wagmi/vue')
      })

@danielroe
Copy link

danielroe commented May 30, 2024

Exactly that kind of thing!

Note that this requires the end user to have installed the dep. If it is a dependency of your module you would do something like your-module > @wagmi/vue, or it won't work without shamefully-hoist.

@yulafezmesi
Copy link
Contributor

hey, adding eventemitter3 to optimizeDeps will solve the issue.

kudos @danielroe

@dej10
Copy link

dej10 commented Aug 1, 2024

hey @yulafezmesi

was this how you added it ?

//nuxt.config.ts


  vite: {
    optimizeDeps: {
      include: ['eventemitter3']
    }
  }

@nwingt
Copy link

nwingt commented Aug 7, 2024

I referred to the pnpm create wagmi and selected the Nuxt template. This seems to be working for me:

// wagmi.ts
import { http, cookieStorage, createConfig, createStorage } from 'wagmi'
import { mainnet, sepolia } from 'wagmi/chains'
import { coinbaseWallet, injected, walletConnect } from 'wagmi/connectors'

export function getConfig() {
  return createConfig({
    chains: [mainnet, sepolia],
    connectors: [
      injected(),
      coinbaseWallet(),
      walletConnect({ projectId: process.env.NEXT_PUBLIC_WC_PROJECT_ID }),
    ],
    storage: createStorage({
      storage: cookieStorage,
    }),
    ssr: true,
    transports: {
      [mainnet.id]: http(),
      [sepolia.id]: http(),
    },
  })
}

declare module 'wagmi' {
  interface Register {
    config: ReturnType<typeof getConfig>
  }
}
// nuxt.config.ts
import { defineNuxtConfig } from 'nuxt/config'

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  devtools: { enabled: true },
  modules: ['@wagmi/vue/nuxt'],
})
// plugins/wagmi.ts
import { VueQueryPlugin } from '@tanstack/vue-query'
import { WagmiPlugin } from '@wagmi/vue'
import { defineNuxtPlugin } from 'nuxt/app'

import { config } from '../wagmi'

// TODO: Move to @wagmi/vue/nuxt nitro plugin
export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(WagmiPlugin, { config }).use(VueQueryPlugin, {})
})

@kristiegiles
Copy link
Contributor

kristiegiles commented Aug 7, 2024

The same error intermittently breaks my builds in Vercel but works on redeploy
Screenshot 2024-08-07 at 12 35 04 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue Misc: Good First Issue
Projects
None yet
Development

No branches or pull requests

8 participants