【发布时间】:2020-08-27 12:13:10
【问题描述】:
这是一个不寻常的问题,但我经常遇到 typescript 编译器(或者可能是 webpack 或相关)的问题。
这发生在我身上大约一天两次(每次的错误信息都不一样):
1.) 我进行正常的代码更改。 2.) 我收到了一些奇怪的莫名其妙的错误 - 最近的是:
第 0 行:解析错误:无法读取未定义的属性“地图”
- 显然,除了 import 语句之外,我的模块中的任何地方的第 0 行都没有代码。但是我检查了我的文件中的各种
.map语句并尝试找到错误,同时重新启动开发服务器几次(同样的错误)。 - 最终,该错误神秘地消失了 - 在这种情况下,我只是注释了我的所有导入语句并在没有更改任何其他内容后不久取消了它们的注释(我没有意外修复该错误)。
现在每天都会发生多次。我使用的是 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"
]
}
【问题讨论】:
标签: reactjs typescript create-react-app