我的项目中不断遇到MaxListeners Exceeded问题,但我找不到解决方案。在导航栏中的页面之间浏览几次时,问题就会出现,单击几次后,控制台会通知MaxListeners问题。我觉得这很奇怪,因为编码没有什么特别之处,我找不到根本原因。
我在Github上创建了一个单独的barebones项目,该项目上只有最低要求的包来尝试隔离问题。看起来web3UIKit、React、Moralis和/或Next之间的配合不太好,但我缺乏100%确定这一点的专业知识。
我想问你的是:你能找到这个问题的原因吗?或者你知道解决这个问题的办法吗。
为了您的方便,我将分享下面的代码并关闭GitHub。如果你能帮助我,我将永远欠你的债。
github克隆:https://github.com/deAgora/maxlisteners.git
_app.js
import { MoralisProvider } from "react-moralis";
import "../styles/globals.css";
function MyApp({ Component, pageProps }) {
return (
<MoralisProvider initializeOnMount={false}>
<Component {...pageProps} />
</MoralisProvider>
);
}
export default MyApp;
Index.js
import Head from "next/head";
import Header from "../components/Header";
import Navbar from "../components/Navbar";
import styles from "../styles/Home.module.css";
export default function Home() {
return (
<div className={styles.container}>
<Head>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</Head>
<Header></Header>
<Navbar></Navbar>
<div>This page is an example to illustrate the maxlisteners issue</div>
</div>
);
}
Page1.js
import Head from "next/head";
import Header from "../components/Header";
import Navbar from "../components/Navbar";
import styles from "../styles/Home.module.css";
export default function Home() {
return (
<div className={styles.container}>
<Head>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</Head>
<Header></Header>
<Navbar></Navbar>
<div>
Page 1: This page is an example to illustrate the maxlisteners issue
</div>
</div>
);
}
组件标题.js
import { ConnectButton } from "@web3uikit/web3";
export default function Header() {
return (
<div className="p-5 border-b-2 flex flex-row bg-slate-400">
<h1 className="py-4 px-4 font-blog text-3xl">Maxlisteners Example</h1>
<div className="ml-auto py-2 px-4">
<ConnectButton moralisAuth={false}></ConnectButton>
</div>
</div>
);
}
组件:Navbar.js
import Link from "next/link";
export default function Navbar() {
return (
<div className="bg-slate-400">
<ul className="grid grid-cols-3 place-items-center py-2 border-b-2 f">
<li>
<Link href="/">
<a>Home</a>
</Link>
</li>
<li>
<Link href="/page1">
<a>Page1</a>
</Link>
</li>
</ul>
</div>
);
}
包.json
{
"name": "maxlisteners",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@web3uikit/core": "^0.1.5",
"@web3uikit/icons": "^0.1.5",
"@web3uikit/web3": "^0.1.5",
"magic-sdk": "^9.0.0",
"moralis": "^2.0.3",
"next": "12.2.5",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-moralis": "^1.4.1"
},
"devDependencies": {
"eslint": "8.22.0",
"eslint-config-next": "12.2.5"
}
}
您好,您正在尝试使用Moralis 2.0(2.0.3(,它无法与react morals一起使用-与以前的SDK(现在称为moralis-v1
(相比,这是一个新的SDK。
您需要在Next.js项目中使用这些版本-moralis@1.11.0
和react-moralis@1.4.0
,因为最新的道德规范-v1和react道德规范存在问题。
如果你对此有更多问题或问题,请在以下网站上发帖:
- 道德不和:https://moralis.io/joindiscord
- 莫拉莱斯论坛:https://forum.moralis.io