简体   繁体   English

解析错误:意外的标记,应为“...”

[英]Parsing error: Unexpected token, expected "..."

I have this code with template literals inside component and I'm getting parsing error from ESLint.我有这个代码,在组件内部有模板文字,我从 ESLint 得到解析错误。 I tried to use @babel/eslint-parser but it doesn't help.我尝试使用 @babel/eslint-parser 但它没有帮助。 Also with this Parsing error: Unexpected token, expected "..." I have '...' expected.ts(1005)还有这个 Parsing error: Unexpected token, expected "..." 我有 '...' expected.ts(1005)

import React from "react";
import { Link } from "react-router-dom";
import logo from "../../images/logo_cl.png";

function Comptetition({ competition }) {
    return (
        <Link to {`/competitions/${competition.id}`}>
            <li className="complist__item">
                <img className="complist__item-image" src={logo} alt="item" />
                <p className="complist__item-name">{competition.name}</p>
                <p className="complist__item-country">{competition.area.name}</p>
            </li>
        </Link>
        
    );
}

export default Comptetition;

my.eslintrc.json looks like this: my.eslintrc.json 看起来像这样:

    {
  "env": {
    "browser": true,
    "jest": true,
    "es6": true,
    "node": true
  },
  "plugins": [
    "import",
    "react"
  ],
  "extends": [
    "eslint:recommended",
    "plugin:react/recommended",
    "airbnb-base",
    "plugin:prettier/recommended"
  ],
  "parser": "@babel/eslint-parser",
  "parserOptions": {
    "ecmaVersion": 12,
    "sourceType": "module",
    "requireConfigFile": false,
    "ecmaFeatures": {
      "jsx": true,
      "modules": true
    },
    "babelOptions": {
      "presets": [
        "@babel/preset-react"
      ]
    }
  },
  "rules": {
    "semi": "error",
    "no-console": "warn",
    "no-eval": "error",
    "import/first": "error",
    "prefer-template": 1,
    "no-param-reassign": [
      2,
      {
        "props": false
      }
    ]
  }
}

I've already read lot of info but cannot resolve this error in VScode我已经阅读了很多信息,但无法在 VScode 中解决此错误

From the code it looks like you're looking at the correct line but the wrong place.从代码看来,您正在查看正确的行,但看错了地方。

You're missing a "=" for value to "to" prop of the Link您缺少链接的“to”属性的“=”

<Link to={`/competitions/${competition.id}`}>

You forget to add = in to你忘记添加= to

to={`/competitions/${competition.id}`}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM