34

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
2
  • 1
    I have the same issue, have you found what causes the error? Commented Mar 18, 2020 at 6:06
  • @Kenjoe the problem went away by itself now. Probably some misconfiguration of peer dependencies of dependencies. Commented Mar 24, 2020 at 8:26

8 Answers 8

30

The problem apparently was caused by a misconfiguration of some (peer?) dependencies of a dependency, 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.

Sign up to request clarification or add additional context in comments.

4 Comments

Weird, upgraded to 3.8.X to no avail, purged node_modules installed again and good to go
Updating TS to 3.8.x fixed my eslint issues, but I kept failing the build until I purged node_modules and my *-lock.json files. I also closed and reopened my IDE just to be sure, and now things are working.
In August 2020, I fixed this by rolling back Typescript to ^3.9.5 after an automatic dependabot upgrade to ^4.0.2. YMMV
If you are experiencing this issue after upgrading to TS 4.0, it is because create-react-app does not yet support TS 4.0 (or more accurately, it's dependencies don't). github.com/facebook/create-react-app/issues/9515 You can fix by downgrading TS, using a pre-release build of CRA 4.0, or force-pinning your ts-eslint an and parser dependencies per github.com/facebook/create-react-app/issues/9515
8

I case of an app generated by

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

More precisely, [email protected]

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

3 Comments

Thanks for the call out for cretae-react-app. Following this solved my problem.
Although, I managed to get the app to compile with yarn as well after a couple of attempts at removing yarn.lock and running yarn
Did it for me! Just removed the node_modules and then yarn, and that was it.
4

Just update typescript version to 3.8.x : Link

2 Comments

Nope, didn't solve mine. Updated to even 3.9 nightly but still the same.
On 4.0, still experiencing the same problem.
3

In my case, I just had to add an extra newline at the end of the ts file.

export * from './result';
export * from './request';
//new line here

Comments

2

In my case, the culprit was asset imports of non-existing files, e.g.:

import { ReactComponent as SomeIcon } from '../assets/img/some-icon.svg';

The answers above helped me find the culprit. I ran rm -rf node_modules package-lock.json && npm i && npm start, which caused the real errors to be shown (instead of the unhelpful cryptic "Line 0: Parsing error: Cannot read property 'name' of undefined")

Once I added the missing files, the errors went away.

Comments

2

This error occurs because your typescript is not compatible with your typescript-eslint plugins.

You can fix it by upgrading these two dependencies to the latest version.

"devDependencies": {
  "@typescript-eslint/eslint-plugin": "^4.6.0",
  "@typescript-eslint/parser": "^4.6.0",
}

Comments

2

Updating react-scripts worked for me. react-scripts 3.4.0 probably does not support typescript 3.7.5

Comments

0

In my case, this was because I had TS code under .\src which was referencing TS code under .\tools but I only had src in the include in my tsconfig.json, adding tools fixed the issue

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.