React Typescript: Line 0: Parsing error: Cannot read property 'name' of undefined

安稳与你 提交于 2020-05-14 16:22:28

问题


Today suddenly I started to get build errors on a project built with Typescript. In a file that (or anything it references) hasn't been changed in weeks, I started to get:

./path/to/my/file.ts
  Line 0:  Parsing error: Cannot read property 'name' of undefined

This error first appeared on our CI, could be replicated by manually building on the server, and I could finally reproduce on my own computer (which was running perfectly) after updating all packages. Now, even if I pull the old (building) commit of my project, I can't build it. I've got yarn.lock commited to my repo, but even with the old package.json and yarn.lock (I delete node_modules and do yarn), I can't build.

This error literally started out of blue today.

What could be the reason?


My (possibly relevant) versions:

yarn 1.22.4,
node v13.11.0,
typescript 3.7.5
react 16.12
react-scripts 3.4.0
macOS 10.15 Catalina

回答1:


The problem apparently was caused by a misconfiguration of some (peer?) dependencies of a dependeny, react-scripts with the TypeScript template. It went away. Make sure you update your dependencies, purge node_modules, even purge package-lock.json or yarn.lock, and try a fresh build again now.




回答2:


Just update typescript version to 3.8.x : Link




回答3:


I case of an app generated by

npx create-react-app my-app --template typescript

More precisely, create-react-app@3.4.1

The issue was solved by running the following command:

rm yarn-lock && rm -rf node_modules && npm i

After which you may run:

either yarn start or npm start



来源:https://stackoverflow.com/questions/60729199/react-typescript-line-0-parsing-error-cannot-read-property-name-of-undefine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!