繁体   English   中英

编译 create-react-app 项目时 TypeScript React 项目不确定的错误

[英]TypeScript React project inconclusive bugs when compiling create-react-app project

这是一个不寻常的问题,但我经常遇到打字稿编译器(或者可能是 webpack 或相关的)的问题。

这发生在我身上大约每天两次(每次的错误消息都不同):

1.) 我做正常的代码更改。 2.) 我收到了一些奇怪的莫名其妙的错误 - 最近的是:

第 0 行:解析错误:无法读取未定义的属性“map”

  1. 显然,除了 import 语句外,我的模块中的第 0 行都没有代码。 但是我检查我的文件中的各种.map语句并尝试找到错误,同时重新启动开发服务器几次(同样的错误)。
  2. 最终,该错误神秘地消失了 - 在这种情况下,我只是评论了我所有的导入语句,并在没有更改任何其他内容后不久取消了它们的注释(我没有意外修复错误)。

这种情况现在一天发生多次。 我使用的是 Typescript 4.0.2,现在我已经降级到 3.9.7。

有什么方法可以“重置”编译器(例如删除临时文件)来解决这个问题? 我真的不知道该怎么做。

我正在使用具有以下依赖项的 create-react-app:

"dependencies": {
    "@date-io/date-fns": "^1.3.13",
    "@date-io/moment": "^1.3.13",
    "@material-ui/core": "^4.11.0",
    "@material-ui/icons": "^4.9.1",
    "@material-ui/lab": "^4.0.0-alpha.56",
    "@material-ui/pickers": "^3.2.10",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/user-event": "^7.1.2",
    "@types/jest": "^24.0.0",
    "@types/lodash": "^4.14.157",
    "@types/node": "^12.0.0",
    "@types/react": "^16.9.41",
    "@types/react-dom": "^16.9.0",
    "@types/react-redux": "^7.1.9",
    "@types/react-router-dom": "^5.1.5",
    "@types/recharts": "^1.8.14",
    "@types/redux-persist": "^4.3.1",
    "@types/styled-components": "^5.1.0",
    "@types/yup": "^0.29.3",
    "axios": "^0.19.2",
    "classnames": "^2.2.6",
    "date-fns": "^2.15.0",
    "formik": "^2.1.5",
    "lodash": "^4.17.15",
    "moment": "^2.27.0",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-intl": "^5.2.1",
    "react-redux": "^7.2.1",
    "react-router-dom": "^5.2.0",
    "react-scripts": "^3.4.1",
    "recharts": "^1.8.5",
    "redux": "^4.0.5",
    "redux-devtools-extension": "^2.13.8",
    "redux-persist": "^6.0.0",
    "redux-thunk": "^2.3.0",
    "styled-components": "^5.1.1",
    "yup": "^0.29.1"
  },
"devDependencies": {
    "@testing-library/react": "^9.5.0",
    "typescript": "^3.9.7"
  }

我的 tsconfig:

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react",
    "noImplicitAny": false,
    "baseUrl": "src"
  },
  "include": [
    "src"
  ]
}

问题是react-scripts使用的是旧版本的 eslint。 关注问题

@typescript-eslint/eslint-plugin": "^2.10.0"
@typescript-eslint/parser": "^2.10.0"

注意手动升级项目中的包不起作用

react-script也给出了对等依赖错误

react-scripts@3.4.3 requires a peer of typescript@^3.9.2 but typescript@^4.0.2 was installed.

现在我们可以降级到typescript@^3.9.2直到react-scripts支持typescript@^4.0

暂无
暂无

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

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