MetaMask Invalid or no prefix found error on network switch

Hello,

I am working on an Next.js dapp, where I am using ConnectKit and Wagmi to connect to the MetaMask wallet. The problem I am facing is that whenever I try to programmatically switch a network I get the following error in MetaMask:
MetaMask encountered an error. Try again by closing and reopening the popup, or contact support here. Error details. Message: Invalid or no prefix found for localhost:3000

Code: Error
Stack:

Error@moz-extension://ac428b0e-f33f-4872-8d8d-9d36707b7bc9/runtime-lavamoat.js:7838:17
n.getSnapPrefix@moz-extension://ac428b0e-f33f-4872-8d8d-9d36707b7bc9/common-1.js:1:75297
F@moz-extension://ac428b0e-f33f-4872-8d8d-9d36707b7bc9/common-7.js:10:158232
t.getSnapName@moz-extension://ac428b0e-f33f-4872-8d8d-9d36707b7bc9/common-7.js:10:158399
x@moz-extension://ac428b0e-f33f-4872-8d8d-9d36707b7bc9/ui-9.js:1:50677
va@moz-extension://ac428b0e-f33f-4872-8d8d-9d36707b7bc9/ui-3.js:1:60111
Mu@moz-extension://ac428b0e-f33f-4872-8d8d-9d36707b7bc9/ui-3.js:1:105038
As@moz-extension://ac428b0e-f33f-4872-8d8d-9d36707b7bc9/ui-3.js:1:90903
Rs@moz-extension://ac428b0e-f33f-4872-8d8d-9d36707b7bc9/ui-3.js:1:90826
xs@moz-extension://ac428b0e-f33f-4872-8d8d-9d36707b7bc9/ui-3.js:1:88166
ti/<@moz-extension://ac428b0e-f33f-4872-8d8d-9d36707b7bc9/ui-3.js:1:46516
n.unstable_runWithPriority@moz-extension://ac428b0e-f33f-4872-8d8d-9d36707b7bc9/ui-3.js:1:514297
Xo@moz-extension://ac428b0e-f33f-4872-8d8d-9d36707b7bc9/ui-3.js:1:46225
ti@moz-extension://ac428b0e-f33f-4872-8d8d-9d36707b7bc9/ui-3.js:1:46463
ei@moz-extension://ac428b0e-f33f-4872-8d8d-9d36707b7bc9/ui-3.js:1:46396
Es@moz-extension://ac428b0e-f33f-4872-8d8d-9d36707b7bc9/ui-3.js:1:88543
dl@moz-extension://ac428b0e-f33f-4872-8d8d-9d36707b7bc9/ui-3.js:1:113785
render@moz-extension://ac428b0e-f33f-4872-8d8d-9d36707b7bc9/ui-3.js:1:115706
a.default/</<@moz-extension://ac428b0e-f33f-4872-8d8d-9d36707b7bc9/ui-8.js:1:199019

In wagmi config I have mainnet and goerli defined as chains. If I am already connected in the browser to my MetaMask wallet to either mainnet or goerli, then when I click on the Connect Wallet button (the button is the official component from ConnectKit) I can connect without any issues. However in case that I was first connected to some other chain that is not defined in the wagmi config, then I will get this error. So lets say I was connected with MetaMask in my browser to Polygon chain and then I try to click on the Connect wallet button, I will not be able to connect and will get the above mentioned error. This same error happens, if I try to programmatically switch network by using wagmi in my app. Generally speaking it seems that as soon as I try to switch networks programmatically I get this error and I can’t seem to fix it. If I try to switch networks manually in MetaMask, I don’t have any issues.

I am not sure if this is a Wagmi or MetaMask issue, I am hoping that someone might be able to look at the MetaMask error and maybe based on that error spot, what could be the issue. I had this same issue last week, back then I was using Rainbowkit and thought that might be causing the issues, so I switched to Web3Modal and that seemed to fix the issue. But today the error returned (while using Web3Modal library), so I tried switching to ConnectKit, but error persists. If anyone has any ideas what might be causing this issues, I would appreciate any advice.

3 Likes

I’m facing the same error and I don’t use libs to switch networks, just calling ethereum.request directly. There is a strange fact that in testing version of our application it works fine but in production or localhost it doesn’t. The problem appeared in the latest version of MetaMask because my co-worker who is still on the previous version had no problems

3 Likes

I had this error with two applications, but in one of them network switching works ok now, but in another it still doesn’t work. It such an odd issue, because in both of this apps I am using the same libraries to connect to the wallet, both are Next.js apps, but in one of them everything works ok (for now) and in the other any sort of network switching results in the mentioned MetaMask error.

2 Likes

I’m having the same problem in my application as well, the staging environment works fine, production environment breaks when we try to switch networks.

The problem first started appearing after MetaMask’s release v11.0.0

This is the error message I get on the MetaMask Extension:

Message: Invalid or no prefix found for "https://luxy.io"

Code: Error

Stack: Error: Invalid or no prefix found for "https://luxy.io"
  at n.getSnapPrefix (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/common-1.js:1:75297)
  at F (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/common-7.js:10:158232)
  at t.getSnapName (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/common-7.js:10:158399)
  at x (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-9.js:1:50677)
  at va (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:60111)
  at Mu (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:105038)
  at As (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:90901)
  at Rs (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:90826)
  at xs (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:88166)
  at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:46516
  at n.unstable_runWithPriority (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:514297)
  at Xo (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:46225)
  at ti (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:46461)
  at ei (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:46396)
  at Es (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:88543)
  at dl (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:113783)
  at render (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:115706)
  at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-8.js:1:199025

The only fix that I could find for this error, was downgrading my MetaMask back to version 10.35.1. I tried various things to fix it, but this seems to be only solution for now, that works for me. As soon as I downgraded the MetaMask version, my app started working OK again and I could switch networks without any issues.

Again, for whatever reason this error initially affected two dapps that I was working on, both used the same libraries to connect to the wallet, but on one of them this error resolved on its own, without any changes added by me. The other dapp only started working after I downgraded my MetaMask wallet to the previous version. So I still don’t know why this error happens, but downgrading MetaMask seems to fix it.

@kpav521 @user32645 @brnzimp

Would you be able to create an issue for it on GitHub here:

Thank you!

1 Like

I created a new issue, it doesn’t let me post a link to it, since I am a new user in this community. The issue has the ID value of #21040, with the title of Invalid or no prefix found error on network switch.

1 Like

I created an issue regarding this bug on MetaMask GitHub issues page. I used your website as an example in the steps to reproduce the bug, since my websites aren’t deployed yet.

Just to let you know, if you haven’t noticed it yet, one way that I found to fix this error, is to downgrade MetaMask to the previous version. I tried to connect to your app through MetaMask wallet on my Firefox browser, which was downgraded to the previous version and network switching works as it should there. But if I try to do the same thing on my Chrome browser, where I have the latest version of MetaMask, the issue persists.

Thanks for creating the GitHub issue, mate!

I understand that downgrading the MetaMask version will work, but for now, this is only something we can recommend to our users, not enforce.

Until the MetaMask team deploys a proper fix, we’re unfortunately in this situation.

1 Like

I’m facing the same issue locally as well as production . Message: Invalid or no prefix found for “”

Code: Error

Stack:
Error: Invalid or no prefix found for “”
at n.getSnapPrefix (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/common-1.js:1:75297)
at F (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/common-7.js:10:158232)
at t.getSnapName (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/common-7.js:10:158399)
at x (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-9.js:1:50677)
at va (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:60111)
at Mu (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:105038)
at As (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:90901)
at Rs (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:90826)
at xs (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:88166)
at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:46516
at n.unstable_runWithPriority (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:514297)
at Xo (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:46225)
at ti (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:46461)
at ei (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:46396)
at Es (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:88543)
at dl (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:113783)
at render (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-3.js:1:115706)
at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-8.js:1:199025

Have you tried updating the version @mpr666

yes I’ve tried updating MetaMask to v 11.1.2 , still facing the same issue. Any workaround for this issue until it’s resolved by MetaMask?

please refer to this merged PR: Only get snap name if it's a snap dialog by GuillaumeRx · Pull Request #21088 · MetaMask/metamask-extension · GitHub and [Bug]: Invalid or no prefix found error on network switch · Issue #21040 · MetaMask/metamask-extension · GitHub

If there is no title’s content of index.html, the error occurs.

<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="title" content="FILL_HERE!" />
...
```

i also git same error if any one please help this issues

you should fill any content of ‘title’ in your index.html

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.