V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
mathzhaoliang
V2EX  ›  程序员

请教一个 ESLint 的报错信息问题

  •  
  •   mathzhaoliang ·
    neozhaoliang · Sep 8, 2022 · 1451 views
    This topic created in 1328 days ago, the information mentioned may be changed or developed.

    如题:我想在网站的 head 标签后面插入 google analytics 代码:

    <div className={styles.container}>
          <Head>
            <script async src="https://www.googletagmanager.com/gtag/js?id=G-86LYXYV8PC"></script>
            <script>
              window.dataLayer = window.dataLayer || [];
              function gtag(){dataLayer.push(arguments);}
              gtag('js', new Date());
              gtag('config', 'G-86LYXYV8PC');
            </script>
            ....
          </Head>  
    </div>
    

    但是给出的报错消息是这样的:

    24:51  Error: Parsing error: '}' expected.
    

    其中 24 行就是 <script async src="https://www.googletagmanager.com/gtag/js?id=G-86LYXYV8PC"></script> 这一行。

    .eslintrc.json 文件内容如下:

    {
      "extends": "next/core-web-vitals",
      "rules": {
        "react-hooks/rules-of-hooks": "off",
        "react/display-name": "off"
      }
    }
    

    请教大家这是什么原因呢?

    Supplement 1  ·  Sep 8, 2022
    问题已解决,是由于在 react 里面直接插入代码导致的。
    DingJZ
        1
    DingJZ  
       Sep 8, 2022
    这玩意没必要写到 react 里面,直接扔到 html 文件里就完了
    mathzhaoliang
        2
    mathzhaoliang  
    OP
       Sep 8, 2022
    @DingJZ 多谢,已经解决了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1326 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 23:46 · PVG 07:46 · LAX 16:46 · JFK 19:46
    ♥ Do have faith in what you're doing.