反应打字稿:第0行:解析错误:无法读取未定义的属性“名称" [英] React Typescript: Line 0: Parsing error: Cannot read property 'name' of undefined

查看:152
本文介绍了反应打字稿:第0行:解析错误:无法读取未定义的属性“名称"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天突然之间,我开始在使用Typescript构建的项目中遇到构建错误.在一个文件(或它所引用的任何内容)在几周内都没有更改的文件中,我开始得到:

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

此错误首先出现在我们的CI上,可以通过在服务器上手动构建来复制,并且在更新所有软件包之后,我终于可以在自己的计算机上运行(运行良好).现在,即使我取消了项目的旧(构建)提交,也无法构建它.我已经将yarn.lock提交到我的仓库中,但是即使使用了旧的package.jsonyarn.lock(我删除了node_modules并执行了yarn),也无法构建.

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.

可能是什么原因?

我(可能相关)的版本:

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

推荐答案

问题显然是由于依赖项react-scripts与TypeScript模板的某些(对等?)依赖项配置错误引起的.它消失了.确保更新依赖关系,清除node_modules,甚至清除package-lock.jsonyarn.lock,然后立即尝试重新构建.

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.

这篇关于反应打字稿:第0行:解析错误:无法读取未定义的属性“名称"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆