wallet-adapter: VueJS "Wallet not initialized" error
Describe the bug Hello, I’m trying to implement “Connect wallet” functionality inside my Vue 3 project. All required packages are up to date and have latest versions.
How to reproduce:
- Create fresh project using Vue CLI (with typescript enabled) -
vue create test-app && cd test-app
- Add following dependencies:
yarn add @solana/wallet-adapter-base @solana/wallet-adapter-wallets @solana/wallet-adapter-vue @solana/wallet-adapter-vue-ui
- Replace App.vue with following
<template>
<wallet-provider auto-connect :wallets="wallets">
<wallet-modal-provider>
<wallet-multi-button></wallet-multi-button>
</wallet-modal-provider>
</wallet-provider>
</template>
<script lang="ts">
import {defineComponent} from 'vue';
import {WalletProvider} from "@solana/wallet-adapter-vue";
import {PhantomWalletAdapter} from "@solana/wallet-adapter-wallets";
import {WalletModalProvider, WalletMultiButton} from "@solana/wallet-adapter-vue-ui";
export default defineComponent({
name: 'App',
components: {
WalletProvider,
WalletMultiButton,
WalletModalProvider,
},
setup() {
// Just one wallet for now
const wallets = [
new PhantomWalletAdapter()
];
return {wallets};
}
});
</script>
- Start development mode
yarn serve
And after opening page in browser, there will be error in console:
Any ideas about this?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 61 (8 by maintainers)
Hey 👋 I’ve just extracted the Vue packages into their own repo (at the request of the maintainers of this repo). The new repo should be all functional so feel free to try it and give some feedback there. Thanks for your patience. 🙂
https://github.com/lorisleiva/solana-wallets-vue
I got it to work with vue-cli.
Both using
<wallet-provider>
or the global store.My dependencies:
App.vue
and then in a route, I have:
This works.
@kyleqian Somehow yes… Using weird hacks in vite.config.js:
Only this way I can create prod build…
I’ll have a look at it tomorrow with a brand new Vue CLI app using the latest packages and see if I can reproduce the issue.
I found the problem https://github.com/solana-labs/wallet-adapter/blob/master/packages/core/vue/src/useWallet.ts#L13, @vue/runtime-core is being used here. I’ll probably raise an issue later today, not sure why it’s being used since the npm page says “This package is published only for typing and building custom renderers. It is NOT meant to be used in applications.”
References that helped me find the problem: https://github.com/highlightjs/vue-plugin/issues/1 https://github.com/vuejs/vue-cli/issues/6327
@NViktors Vite explicitly does not support Node polyfills or any libraries that expect them. Some dependencies of the various wallet providers do expect Node built-ins to be available and, as such, make Vite fail. That’s why I currently stick to Webpack 5 for Solana development and explicitly configure the polyfills I need and discard the ones I don’t.
@NViktors and also,
yarn build
does not work with Vite. Also checked on your repo.Something wrong with
@blocto/sdk/dist/blocto-sdk.module.js
.Do you confirm?
Sounds like this is resolved then?
@florentchauveau https://github.com/NViktors/vite-wallet-test - I created repo with working example using Vite. Feel free to check if that works for you.
@NViktors Got it… yeah it still wasn’t working for me. I ended up switching completely to Next and have had no issues since.
@NViktors @florentchauveau
Did either of you ever get the vite build working? I’m running into the same issue:
Right, the whole point is that I shouldn’t have to do that and that’s what the PR is for. The latest version of all packages should always be compatible with each other IMO
@lorisleiva thanks for helping.
I’ve never used Vite (the use of it in the vue-ui package here is all thanks to Loris) so I’m afraid I can’t help.
I used to use Webpack / Babel a lot, but these days I generally try to use build tools that are batteries-included / low config / fast like Next / Parcel / esbuild / tsc unless I know I need to customize it. It’s just not worth to deal with the hassle.
Thank you @jordansexton for the fix on vue builds.
However, even when using
I still get the
Error: Wallet not initialized. Please use the WalletProvider component to initialize the wallet.
.How about you @NViktors?
My package.json:
I am trying old versions.
Published:
You’ll still need to use:
I do not have the error with the global store approach, but another error when using the wallet:
SFC:
However, choosing a wallet does not do anything. And using the wallet returns the error:
@NViktors can you reproduce?
I have the same issue. It seems that the Vue libraries are broken right now.
Maybe @lorisleiva can help us here 😃
@NViktors here is an working example, but with outdated libs: https://lorisleiva.com/create-a-solana-dapp-from-scratch/integrating-with-solana-wallets