相关文章推荐
乐观的桔子  ·  C++ ...·  1 年前    · 
知识渊博的哑铃  ·  jquery 修改iframe ...·  1 年前    · 
不拘小节的皮带  ·  Django REST framework ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Angular: node_modules/@types/babel _traverse/index.d.ts(1137,43): error TS1109: Expression expected

Ask Question

I am currently stucked in very weird issue in Angular. I was working on one my branch a week ago it was fine and building correctly. But I don't know how it start complaing during 'ng build' below is the error I am keep getting today:

node_modules/@types/babel__traverse/index.d.ts(1136,44): error TS1109: Expression expected.
node_modules/@types/babel__traverse/index.d.ts(1137,21): error TS1109: Expression expected.
node_modules/@types/babel__traverse/index.d.ts(1137,37): error TS1005: ';' expected.
node_modules/@types/babel__traverse/index.d.ts(1137,43): error TS1109: Expression expected.
node_modules/@types/babel__traverse/index.d.ts(1139,1): error TS1128: Declaration or statement expected.

I tried below options to fix this but didn't get any success:

Option 1 - removing and installing node_modules, Option 2 - removing and installing @types/babel_traverse

Can anyone let me know what could be the reason. Here are my local angular/dependancy installed versions:

Angular CLI: 7.3.10
Node: 8.15.0
OS: win32 x64
Angular: 7.2.15
... animations, common, compiler, compiler-cli, core, elements
... forms, http, language-service, platform-browser
... platform-browser-dynamic, router, service-worker
Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.13.10
@angular-devkit/build-angular      0.13.9
@angular-devkit/build-ng-packagr   0.13.9
@angular-devkit/build-optimizer    0.13.9
@angular-devkit/build-webpack      0.13.9
@angular-devkit/core               7.3.10
@angular-devkit/schematics         7.3.10
@angular/cdk                       7.3.7
@angular/cli                       7.3.10
@angular/material                  7.3.7
@angular/material-moment-adapter   7.3.7
@ngtools/json-schema               1.1.0
@ngtools/webpack                   7.3.9
@schematics/angular                7.3.10
@schematics/update                 0.13.10
ng-packagr                         4.7.1
rxjs                               6.3.3
typescript                         3.2.1
webpack                            4.29.0

Please note that I can't update anything at this point because my project is already in production.

Many thanks in advance.

I had to add "@types/babel__traverse": "7.0.13" in my package.json as a temporary solution. But I am still debugging to fix this issue permanently. – tutorialfeed Sep 16, 2020 at 6:38 OP said he cannot do this: "Please note that I can't update anything at this point because my project is already in production." – Ozone Sep 29, 2020 at 10:31 This answer works, can be because of a bad version of typescript... if you cannot update anything in production, how can you fix the problem.... – Ben Winding Oct 7, 2020 at 6:03 The problem went away for me when I updated to the latest: npm install typescript@latest -D – Chris Livdahl Sep 21, 2021 at 15:44 This worked for me, even though I was already on a version higher than the OP's. I wonder if it's something about the upgrade process itself...? – Andrew Dec 8, 2022 at 21:09

I had the same problem and I found a way to bypass the issue but I have to warn, it's a patch not a fix. The way to get over this is simple, just download/install an older version of @types/babel__traverse following these steps

  • install an older version (I used 7.0.6) by running the command npm install @types/babel__traverse@7.0.6
  • Note: you might want to install that in a separate project or folder so that running a full npm install won't overwrite it to the latest version again.
  • then go into that temp lib folder \node_modules\@types\babel__traverse and simply copy the index.d.ts file
  • then go into the broken project and overwrite the file (\node_modules\@types\babel__traverse\index.d.ts)
  • and voilà it works!!!

    [Q] So why do we have to do that?

    [A] It's very simple, the index.d.ts file produced by TypeScript older than 3.5.x is quite different (its structure is different) compare to newer TypeScript > 3.5.x

    [Q] Ok but why can't I just add @types/babel__traverse to my package.json and be done with it?

    [A] Because the Babel team decided to use "@types/babel__traverse": "*" and that little * means always download latest version... in other words, Thanks You Babel Team I'm not so happy (sic) to report that you broke my code by being explicit to always use your latest version :( ...and here's the proof, taken from my yarn.lock file

    "@types/babel__core@^7.1.0":
      version "7.1.10"
      resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.10.tgz#ca58fc195dd9734e77e57c6f2df565623636ab40"
      integrity sha512-x8OM8XzITIMyiwl5Vmo2B1cR1S1Ipkyv4mdlbJjMa1lmuKvKY9FrBbEANIaMlnWn5Rf7uO+rC/VgYabNkE17Hw==
      dependencies:
        "@babel/parser" "^7.1.0"
        "@babel/types" "^7.0.0"
        "@types/babel__generator" "*"
        "@types/babel__template" "*"
        "@types/babel__traverse" "*"
    

    Take a look at the last line with * ­­­­­­↑

    Final Word

    In Conclusion, the real fix is to update your TypeScript to version newer than 3.5.x but if you can't (like me), well then follow the 3 steps I wrote and you'll be back in business.

    This worked for me. In my case, the dependency was @types/babel-types. It was compiled with 3.7 typescript version. later I have installed and copied the index.d.ts file which was compiled in 3.5. – swyrik Jan 12, 2022 at 3:27 You can instead add "resolutions": { "@types/babel__traverse": "7.0.6" } to your package.json to force "@types/babel__traverse" "*" to resolve to "@types/babel__traverse": "7.0.6" which has the same effect as above but is a fix not a patch. – Gifford N. Dec 6, 2022 at 5:58 Also just a point of clarification @types/* packages are maintained by the DefinitelyTyped org and volunteer contributors, not the Babel Team, and are very receptive to pull requests :) – Gifford N. Dec 6, 2022 at 6:21

    to your package.json to force "@types/babel__traverse": "*" to resolve to "@types/babel__traverse": "7.0.6".

    Methology:

    Because @types/babel__core dependencies list contains @types/babel__traverse with a version set to '*' (aka latest) even if you specify a version for @types/babel__traverse in package.json, @types/babel__core will install the latest version of @types/babel__traverse in its own dependency chain.

    By using resolutions we can specify strict restrictions for dependencies of dependencies.

    This seems like the safest route and it worked for me. "Update ts version" sounds like a shotgun approach. – aknosis Feb 20 at 18:27

    The different releases of @types/babel__traverse and @types/babel__core are tagged with the TypeScript versions they support.

    Visit https://www.npmjs.com/package/@types/babel__traverse?activeTab=versions and https://www.npmjs.com/package/@types/babel__core?activeTab=versions respectively and look at the tsX.Y tags listed next to each release, for which TypeScript version it supports.

    You need to look these up manually (I don't know how to do this automatically, though it feels like there should be a way) and then configure the compatible versions by hand in package.json, e.g.

        "typescript": "^3.9.10",
        "@types/babel__core": "7.1.19",
        "@types/babel__traverse": "7.17.1",
                    Thanks for reply but luckily issue is not in prod right now. But I noticed that third party component which I am using switched their dependency base from npm to yarn. So this might be the reason.
    – tutorialfeed
                    Sep 23, 2020 at 7:21
            

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.