V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
mathzhaoliang
V2EX  ›  程序员

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

  •  
  •   mathzhaoliang ·
    neozhaoliang · 2022-09-08 15:23:20 +08:00 · 603 次点击
    这是一个创建于 588 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如题:我想在网站的 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"
      }
    }
    

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

    第 1 条附言  ·  2022-09-08 19:01:54 +08:00
    问题已解决,是由于在 react 里面直接插入代码导致的。
    DingJZ
        1
    DingJZ  
       2022-09-08 18:15:58 +08:00
    这玩意没必要写到 react 里面,直接扔到 html 文件里就完了
    mathzhaoliang
        2
    mathzhaoliang  
    OP
       2022-09-08 19:01:23 +08:00
    @DingJZ 多谢,已经解决了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5403 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 08:08 · PVG 16:08 · LAX 01:08 · JFK 04:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.