reactjs - איך לפתור שגיאת ניתוח בעת ייצוא סוג בסביבה של CRA עם TypeScript


אני בונה אפליקציה עם התבנית של CRA ב-TypeScript.

כאשר השתמשתי בקוד הזה, יש שגיאת ניתוח.

export type { BaseModalProps } from "./BaseModalProps"
Parsing error: Declaration or statement expected

אלה חלק מ-package.json שלי ו-.eslintrc

// package.json
"dependencies": {
    "@craco/craco": "^5.6.4",
    "@material-ui/core": "^4.11.0",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "@types/jest": "^24.0.0",
    "@types/node": "^12.0.0",
    "@types/react": "^16.9.0",
    "@types/react-dom": "^16.9.0",
    "axios": "^0.20.0",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-facebook-login": "^4.1.1",
    "react-google-login": "^5.1.21",
    "react-hook-form": "^6.8.1",
    "react-redux": "^7.2.1",
    "react-router-dom": "^5.2.0",
    "react-scripts": "3.4.1",
    "redux": "^4.0.5",
    "redux-logger": "^3.0.6",
    "redux-persist": "^6.0.0",
    "redux-saga": "^1.1.3",
    "styled-components": "^5.1.1",
    "styled-reset": "^4.2.1"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@types/react-facebook-login": "^4.1.2",
    "@types/react-redux": "^7.1.9",
    "@types/react-router-dom": "^5.1.5",
    "@types/redux-logger": "^3.0.8",
    "@types/styled-components": "^5.1.2",
    "@typescript-eslint/eslint-plugin": "^4.1.0",
    "@typescript-eslint/parser": "^4.1.0",
    "craco-alias": "^2.1.1",
    "eslint-config-airbnb": "^18.2.0",
    "eslint-config-prettier": "^6.11.0",
    "eslint-plugin-import": "^2.22.0",
    "eslint-plugin-jsx-a11y": "^6.3.1",
    "eslint-plugin-prettier": "^3.1.4",
    "eslint-plugin-react": "^7.20.5",
    "eslint-plugin-react-hooks": "^4.0.8",
    "husky": ">=4",
    "lint-staged": ">=10",
    "prettier": "^2.1.1",
    "typescript": "^4.0.2"
  },
// .eslintrc
  "env": {
    "browser": true,
    "es2020": true
  },
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint", "react"],
  "extends": [
    "plugin:react/recommended",
    "airbnb",
    "prettier/react",
    "plugin:prettier/recommended",
    "plugin:@typescript-eslint/recommended"
  ],
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true,
      "tsx": true,
      "ts": true,
      "d.ts": true
    },
    "ecmaVersion": 11,
    "sourceType": "module"
  },

איך אני יכול לפתור את זה?

תשובה #1

אני לא בדיוק בטוח איך לתקן אז כיבית והפעלתי מחדש.

/* eslint-disable */
export type { BaseModalProps } from "./BaseModalProps"
/* eslint-enable */

אלטרנטיבה :

במחקר שלי, הרבה אנשים הצליחו לתקן על ידי טעינת הסביבה שלהם מחדש. אנחנו יכולים לעשות זאת ב-VS Code על ידי:

  1. cmd+shift+p (ctrl+shift+p)
  2. >Reload Window
  3. להיכנס

זה יטען מחדש את חלון VS Code שבו אתה נמצא כאילו פתחת זה עתה את הפרויקט.