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"
  },

我该如何解决这个问题?

最佳答案

我不确定如何修复所以我 disabled and enabled .

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

备选方案:

在我的研究中,很多人都能够通过重新加载他们的环境来修复。我们可以通过以下方式在 VS Code 中执行此操作:

  1. cmd+shift+p (ctrl+shift+p)
  2. >重新加载窗口
  3. 进入

这将重新加载您所在的 VS Code 窗口,就像您刚刚打开项目一样。

https://stackoverflow.com/questions/63871179/

相关文章:

python - 使用 tokenizer.encode_plus 时遇到问题

gradle - React Native 项目 Android Gradle Fail (Reac

javascript - 如何在 react 中的不同组件库之间共享上下文?

postgresql - Cloud SQL (postgres) 外部数据包装器连接超时到副本实例

tensorflow - Keras SavedModel 与 Tensorflow SavedMo

javascript - select2 on select data-select2-id 属性添

python-3.x - 如何创建 swagger :response that produces

flutter - 如何在 Flutter 中绘制尖三角形边?

python - 为什么 Keras 不返回 lstm 层中细胞状态的完整序列?

javascript - 使用逗号自动格式化数字时如何保留预期的光标位置?