Ошибка синтаксического анализа: ключевое слово ‘const’ зарезервировано

#typescript #next.js #eslint

#typescript #next.js #eslint

Вопрос:

Я пытаюсь установить linting в свой проект, и по какой-то причине я получаю эту ошибку при каждом запуске npm run lint . Я использую фреймворк nextjs (React) и прикрепил свою ошибку, файл package.json и .eslintrc.json.

Ошибка, которую я получаю

 /home/vikky/fruit-seller-a-frontend/tests/index.test.tsx


1:1  error  Parsing error: The keyword 'import' is reserved

✖ 12 problems (12 errors, 0 warnings)

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! fruit-seller-a-frontend@0.1.0 lint: `eslint . --ext ts --ext js --ext tsx`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the fruit-seller-a-frontend@0.1.0 lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/vikky/.npm/_logs/2020-12-07T11_20_27_455Z-debug.log
 

Вот как выглядит мой файл .eslintrc.json.

 {
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "ecmaVersion": 7,
        "sourceType": "module",
        "ecmaFeatures": {
            "jsx": true,
            "tsx": true,
            "ts": true,
            "modules": true
        }
    },
    "plugins": [
        "@typescript-eslint",
        "react"
    ],
    "extends": [
        "eslint:recommended",
        "plugin:react/recommended",
        "plugin:@typescript-eslint/recommended"
        // Uncomment the following lines to enable eslint-config-prettier
        // Is not enabled right now to avoid issues with the Next.js repo
        // "prettier",
        // "prettier/@typescript-eslint"
    ],
    "env": {
        "es6": true,
        "browser": true,
        "jest": true,
        "node": true
    },
    "rules": {
        "react/react-in-jsx-scope": 0,
        "react/display-name": 0,
        "react/prop-types": 0,
        "@typescript-eslint/explicit-function-return-type": 0,
        "@typescript-eslint/explicit-member-accessibility": 0,
        "@typescript-eslint/indent": 0,
        "@typescript-eslint/member-delimiter-style": 0,
        "@typescript-eslint/no-explicit-any": 0,
        "@typescript-eslint/no-var-requires": 0,
        "@typescript-eslint/no-use-before-define": 0,
        "@typescript-eslint/no-unused-vars": [
            2,
            {
                "argsIgnorePattern": "^_"
            }
        ],
        "no-console": [
            2,
            {
                "allow": [
                    "warn",
                    "error"
                ]
            }
        ]
    }
}
 

package.json

 {
  "name": "fruit-seller-a-frontend",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "test": "jest --coverage",
    "test:watch": "jest --watch --coverage",
    "test:coverage": "jest --coverage --no-cache --coverageReporters="text-summary"",
    "lint": "eslint . --ext ts --ext js --ext tsx",
    "lint.fix": "eslint --fix --ext .js --ext .ts --ext .tsx ./"
  },
  "dependencies": {
    "autoprefixer": "^10.0.4",
    "axios": "^0.21.0",
    "next": "10.0.3",
    "postcss": "^8.1.10",
    "react": "17.0.1",
    "react-dom": "17.0.1",
    "react-query": "^2.26.4",
    "tailwindcss": "^2.0.1"
  },
  "devDependencies": {
    "@testing-library/dom": "^7.28.1",
    "@testing-library/jest-dom": "^5.11.6",
    "@testing-library/react": "^11.2.2",
    "@types/jest": "^26.0.16",
    "@types/node": "^14.14.10",
    "@types/react": "^17.0.0",
    "@types/react-query": "^1.1.2",
    "@typescript-eslint/eslint-plugin": "^4.9.0",
    "@typescript-eslint/parser": "^4.9.0",
    "babel-jest": "^26.6.3",
    "eslint": "^7.15.0",
    "eslint-config-standard": "^16.0.2",
    "eslint-plugin-import": "^2.22.1",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-promise": "^4.2.1",
    "eslint-plugin-react": "^7.21.5",
    "jest": "^26.6.3",
    "jest-watch-typeahead": "^0.6.1",
    "prettier": "^2.2.1",
    "typescript": "^4.1.2"
  }
}
 

Пожалуйста, помогите мне! Спасибо!

Комментарии:

1. на самом деле, вы получаете сообщение об ошибке «Ошибка синтаксического анализа: ключевое слово ‘import’ зарезервировано». вы не возражаете, если я изменю название вопроса?