Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@babel/types 7.12.11 causes syntax error on TypeScript 3.2.4 #12519

Closed
miestr opened this issue Dec 17, 2020 · 13 comments · Fixed by #12521
Closed

@babel/types 7.12.11 causes syntax error on TypeScript 3.2.4 #12519

miestr opened this issue Dec 17, 2020 · 13 comments · Fixed by #12521
Labels
Flow -> TS Tracking repository migration from Flow to TS i: bug i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: types

Comments

@miestr
Copy link

miestr commented Dec 17, 2020

Bug Report

Current behavior
I use babel in a react application. When trying to produce a build (yarn run build), it fails with error code:
TypeScript error in /var/jenkins/.../node_modules/@babel/types/lib/index.d.ts(1450,50):
'{' or ';' expected. TS1144

      1448 | }): ReturnedChild[];
      1449 | 
    > 1450 | declare function assertNode(node?: any): asserts node is Node;
           |                                                  ^
      1451 | 

As a current fix I declared a yarn resolution to use version 7.12.10, which compiles without any issues.

- Babel version:  v7.12.11
- Node 10.15.3, yarn 1.22.4, typescript 3.2.4
- OS: Windows 10
- How you are using Babel: webpack
- ```
@babel-bot
Copy link
Collaborator

Hey @miestr! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

@nicolo-ribaudo nicolo-ribaudo added Flow -> TS Tracking repository migration from Flow to TS i: regression pkg: types and removed i: needs triage labels Dec 17, 2020
@miestr
Copy link
Author

miestr commented Dec 17, 2020 via email

@nicolo-ribaudo
Copy link
Member

(I deleted my reply as soon as I posted it because I noticed you already mentioned it 😅)

We specify typesVersions in out package.json (https://unpkg.com/browse/@babel/types@7.12.11/package.json), so I'm surprised that TS is reading that index.d.ts file 🤔

@JLHwung
Copy link
Contributor

JLHwung commented Dec 17, 2020

I think typeVersions does not work on legacy typescript versions. There was the reason why we specified >3.7 before 7.12.11.

@AviVahl
Copy link
Contributor

AviVahl commented Dec 17, 2020

IIRC ts@3.2's support for typeVersions was kinda broken. The thing is, even DefinitelyTyped dropped support for that version already, per https://github.com/DefinitelyTyped/DefinitelyTyped#older-versions-of-typescript-31-and-earlier allowing them to start using that feature more widespread, as all supported ts versions of DT now handle typeVersions properly.

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Dec 17, 2020

I have a fix for this, I will open a PR when I get home later (the code is already there, but I just turned off the PC 😛).

I was surprised because typesVersions has been introduced in 3.1, and the OP is using 3.2.

@salvoravida

This comment has been minimized.

@AviVahl
Copy link
Contributor

AviVahl commented Dec 17, 2020

@salvoravida
You can avoid your CI breaking by using lock files and not picking up new versions automatically... Lock files are there so we can continue working while addressing any compatibility issues that rise due to new versions. Works well for my team.

I cannot imagine working on a project using ts@3.2 without lock files. It could break at any second due to @types packages already dropping their support. @babel is just the current victim/offender.

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Dec 17, 2020

@salvoravida Every time you comment in this repository you do so sarcastically, pretending we owe you something (hint: we do not!). Unless you want to be collaborative, you are not welcome to interact in this repository.

PS. I already recommended you to use lockfiles.

@sawo
Copy link

sawo commented Dec 17, 2020

It might sound silly, but as soon as I reformatted the index.d.ts file and the function declarations broke into multiple lines,
the errors disappeared and I was able to compile.

@nicolo-ribaudo
Copy link
Member

As another workaround until we release a fix, you can copy the contents of @babel/types/lib/index-ts3.7.d.ts into @babel/types/lib/index.d.ts.

@JLHwung JLHwung changed the title Version 7.12.11 does not compile @babel/types 7.12.11 causes syntax error on TypeScript 3.2.4 Dec 17, 2020
@DJmRek
Copy link

DJmRek commented Dec 17, 2020

Guys you saved me today! Had a similar error cause by typescript 3.4.5 and @bable/types. Thanks
/sparkle @nicolo-ribaudo
/sparkle @AviVahl

@mihanizm56
Copy link

get a temp
image
fix by providing the oldest version in "resolutions" field in package.json
awaiting for the fix
ts version 3.6.4
cra v3.4.3 with --typescript

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Mar 21, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Flow -> TS Tracking repository migration from Flow to TS i: bug i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: types
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants