“Every click produces Uncaught TypeError: Cannot read properties of undefined (reading ‘0’)”

huangapple go评论76阅读模式
英文:

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 &#39;0&#39;)
at Array.&lt;anonymous&gt; (content.js:7:89199)
at c.trigger (content.js:7:81786)
at HTMLDocument.&lt;anonymous&gt; (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 &quot;react-dom/client&quot;;
import &quot;./index.css&quot;;
import App from &quot;./App&quot;;
import { AxiosInterceptor } from &quot;./interceptors/axios.interceptor&quot;;
AxiosInterceptor();
const root = ReactDOM.createRoot(document.getElementById(&quot;root&quot;)!)!;
root.render(&lt;App /&gt;);

My App.tsx

import { BrowserRouter as Router, Route, Navigate } from &quot;react-router-dom&quot;;
import Landing from &quot;./pages/landing/Landing&quot;;
import Sidebar from &quot;./components/Sidebar/Sidebar&quot;;
import Footer from &quot;./components/Footer/Footer&quot;;
import { PrivateRoutes, PublicRoutes } from &quot;./models&quot;;
import { AuthGuard } from &quot;./guards&quot;;
import { RoutesWithNotFound } from &quot;./utilities&quot;;
import { lazy, Suspense } from &quot;react&quot;;
import { Provider } from &quot;react-redux&quot;;
import store from &quot;./redux/store&quot;;
import { LinkedInCallback } from &quot;react-linkedin-login-oauth2&quot;;
const Login = lazy(() =&gt; import(&quot;./pages/login/Login&quot;));
const Signup = lazy(() =&gt; import(&quot;./pages/signup/Signup&quot;));
const Private = lazy(() =&gt; import(&quot;./pages/private/Private&quot;));
function App() {
return (
&lt;Suspense
fallback={
&lt;div className=&quot;flex items-center h-screen justify-center&quot;&gt;
&lt;div className=&quot;w-16 h-16 border-4 border-dashed rounded-full animate-spin border-red-600&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
}
&gt;
&lt;Provider store={store}&gt;
&lt;Router&gt;
&lt;Sidebar /&gt;
&lt;RoutesWithNotFound&gt;
&lt;Route path=&quot;/&quot; element={&lt;Navigate to={PrivateRoutes.PRIVATE} /&gt;} /&gt;
&lt;Route path={PublicRoutes.LANDING} element={&lt;Landing /&gt;} /&gt;
&lt;Route path={PublicRoutes.LOGIN} element={&lt;Login /&gt;} /&gt;
&lt;Route
path={PublicRoutes.LINKEDIN_LOGIN}
element={&lt;LinkedInCallback /&gt;}
/&gt;
&lt;Route
path={PublicRoutes.LINKEDIN_REGISTER}
element={&lt;LinkedInCallback /&gt;}
/&gt;
&lt;Route path={PublicRoutes.SIGNUP} element={&lt;Signup /&gt;} /&gt;
&lt;Route element={&lt;AuthGuard /&gt;}&gt;
&lt;Route
path={`${PrivateRoutes.PRIVATE}/*`}
element={&lt;Private /&gt;}
/&gt;
&lt;/Route&gt;
&lt;/RoutesWithNotFound&gt;
&lt;Footer /&gt;
&lt;/Router&gt;
&lt;/Provider&gt;
&lt;/Suspense&gt;
);
}
export default App;

The file pointed by the error is this one (last line is responsible for the error apparently)

“Every click produces Uncaught TypeError: Cannot read properties of undefined (reading ‘0’)”

答案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.)

huangapple
  • 本文由 发表于 2023年2月10日 04:32:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75404142.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定