英文:
Every click produces Uncaught TypeError: Cannot read properties of undefined (reading '0')
问题
我的网站React工作正常,但我正在尝试修复这个控制台错误。每次点击都会产生以下错误:
Uncaught TypeError: Cannot read properties of undefined (reading '0')
at Array.<anonymous> (content.js:7:89199)
at c.trigger (content.js:7:81786)
at HTMLDocument.<anonymous> (content.js:7:81253)
无论在网站的哪个位置。
我尝试删除组件,看它是否来自特定的某个地方,但最终我删除了整个app.js的内容,仍然发生这个错误。
有什么建议可以寻找问题所在吗?
我使用的是React + Vite + Typescript + Tailwind。
我的main.tsx:
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
import { AxiosInterceptor } from "./interceptors/axios.interceptor";
AxiosInterceptor();
const root = ReactDOM.createRoot(document.getElementById("root")!)!;
root.render(<App />);
我的App.tsx:
import { BrowserRouter as Router, Route, Navigate } from "react-router-dom";
import Landing from "./pages/landing/Landing";
import Sidebar from "./components/Sidebar/Sidebar";
import Footer from "./components/Footer/Footer";
import { PrivateRoutes, PublicRoutes } from "./models";
import { AuthGuard } from "./guards";
import { RoutesWithNotFound } from "./utilities";
import { lazy, Suspense } from "react";
import { Provider } from "react-redux";
import store from "./redux/store";
import { LinkedInCallback } from "react-linkedin-login-oauth2";
const Login = lazy(() => import("./pages/login/Login"));
const Signup = lazy(() => import("./pages/signup/Signup"));
const Private = lazy(() => import("./pages/private/Private"));
function App() {
return (
<Suspense
fallback={
<div className="flex items-center h-screen justify-center">
<div className="w-16 h-16 border-4 border-dashed rounded-full animate-spin border-red-600"></div>
</div>
}
>
<Provider store={store}>
<Router>
<Sidebar />
<RoutesWithNotFound>
<Route path="/" element={<Navigate to={PrivateRoutes.PRIVATE} />} />
<Route path={PublicRoutes.LANDING} element={<Landing />} />
<Route path={PublicRoutes.LOGIN} element={<Login />} />
<Route
path={PublicRoutes.LINKEDIN_LOGIN}
element={<LinkedInCallback />}
/>
<Route
path={PublicRoutes.LINKEDIN_REGISTER}
element={<LinkedInCallback />}
/>
<Route path={PublicRoutes.SIGNUP} element={<Signup />} />
<Route element={<AuthGuard />}>
<Route
path={`${PrivateRoutes.PRIVATE}/*`}
element={<Private />}
/>
</Route>
</RoutesWithNotFound>
<Footer />
</Router>
</Provider>
</Suspense>
);
}
export default App;
错误指向的文件是这个(最后一行显然是错误的原因):
英文:
my website React works correctly but I'm trying to fix this console error.
Every click produces this:
Uncaught TypeError: Cannot read properties of undefined (reading '0')
at Array.<anonymous> (content.js:7:89199)
at c.trigger (content.js:7:81786)
at HTMLDocument.<anonymous> (content.js:7:81253)
No matter where in the website.
I tried to remove components and see if it was coming from something in particular but I ended up removing the whole app.js content and it's still happening.
Any idea for what to look for?
I'm using React + Vite + Typescript + Tailwind
My main.tsx
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
import { AxiosInterceptor } from "./interceptors/axios.interceptor";
AxiosInterceptor();
const root = ReactDOM.createRoot(document.getElementById("root")!)!;
root.render(<App />);
My App.tsx
import { BrowserRouter as Router, Route, Navigate } from "react-router-dom";
import Landing from "./pages/landing/Landing";
import Sidebar from "./components/Sidebar/Sidebar";
import Footer from "./components/Footer/Footer";
import { PrivateRoutes, PublicRoutes } from "./models";
import { AuthGuard } from "./guards";
import { RoutesWithNotFound } from "./utilities";
import { lazy, Suspense } from "react";
import { Provider } from "react-redux";
import store from "./redux/store";
import { LinkedInCallback } from "react-linkedin-login-oauth2";
const Login = lazy(() => import("./pages/login/Login"));
const Signup = lazy(() => import("./pages/signup/Signup"));
const Private = lazy(() => import("./pages/private/Private"));
function App() {
return (
<Suspense
fallback={
<div className="flex items-center h-screen justify-center">
<div className="w-16 h-16 border-4 border-dashed rounded-full animate-spin border-red-600"></div>
</div>
}
>
<Provider store={store}>
<Router>
<Sidebar />
<RoutesWithNotFound>
<Route path="/" element={<Navigate to={PrivateRoutes.PRIVATE} />} />
<Route path={PublicRoutes.LANDING} element={<Landing />} />
<Route path={PublicRoutes.LOGIN} element={<Login />} />
<Route
path={PublicRoutes.LINKEDIN_LOGIN}
element={<LinkedInCallback />}
/>
<Route
path={PublicRoutes.LINKEDIN_REGISTER}
element={<LinkedInCallback />}
/>
<Route path={PublicRoutes.SIGNUP} element={<Signup />} />
<Route element={<AuthGuard />}>
<Route
path={`${PrivateRoutes.PRIVATE}/*`}
element={<Private />}
/>
</Route>
</RoutesWithNotFound>
<Footer />
</Router>
</Provider>
</Suspense>
);
}
export default App;
The file pointed by the error is this one (last line is responsible for the error apparently)
答案1
得分: 11
这个错误与 content.js 相关。
这是一个可以与浏览器访问的网页交互的脚本(参见 https://developer.chrome.com/docs/extensions/mv3/content_scripts)
这个错误仅在 Chrome 中发生。我正在使用 Chrome 109.0.5414.119 版本。原因在于一个扩展。将 Chrome 扩展中的设置 'Typio Form Recovery' 中的 'Access to site' 更改为特定站点而不是所有站点或 'on click' 可以解决问题。
错误的原因不在于应用程序代码,而是在 Chrome 扩展中。
(同样的错误在每次点击时在一个 Angular 应用中发生。上面列表中唯一的共同依赖项是 TypeScript。我正在使用 TypeScript 4.9.4。)
英文:
The error relates to content.js.
This is a script that can interact with web pages that the browser visits (See e.g. https://developer.chrome.com/docs/extensions/mv3/content_scripts)
The error occurs in Chrome only. I am using Chrome 109.0.5414.119. The cause is in an extension. Changing the setting in Chrome extension 'Typio Form Recovery' named 'Access to site' into a specific site instead of all sites or 'on click' solves the issue.
Cause of the error is not in the app code but in Chrome extension.
(Same error occurs in an Angular app at every click. The only common dependency from the list above is TypeScript. I am using TypeScript 4.9.4.)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论