反应打字稿:第0行:解析错误:无法读取未定义的属性“名称" [英] React Typescript: Line 0: Parsing error: Cannot read property 'name' of undefined
问题描述
今天突然之间,我开始在使用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.json
和yarn.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.json
或yarn.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屋!