Error TS1005: ';' expected. TypeScript Ang

2020-05-16 12:56发布

问题:

I'm building my first Angular Application. I'm creating a new Angular application using this command ng new purchase-section. But when I executing the application using ng serve -o I got the following error.

ERROR in node_modules/rxjs/internal/types.d.ts(81,44): error TS1005: ';' expected. node_modules/rxjs/internal/types.d.ts(81,74): error TS1005: ';' expected. node_modules/rxjs/internal/types.d.ts(81,77): error TS1109: Expression expected.

I have inspected types.d.ts as I know it is created by Angular. I'm not able to understand the error. Note that after I got this error I deleted node_modules and I installed using npm install wished I got away still I got this error.

Here is my package.JSON file:

{
 "name": "purchase-section",
 "version": "0.0.0",
  "scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
 },
 "private": true,
   "dependencies": {
    "@angular/animations": "^6.0.3",
     "@angular/common": "^6.0.3",
     "@angular/compiler": "^6.0.3",
     "@angular/core": "^6.0.3",
     "@angular/forms": "^6.0.3",
      "@angular/http": "^6.0.3",
      "@angular/platform-browser": "^6.0.3",
      "@angular/platform-browser-dynamic": "^6.0.3",
      "@angular/router": "^6.0.3",
       "core-js": "^2.5.4",
       "rxjs": "^6.0.0",
        "zone.js": "^0.8.26"
       },
      "devDependencies": {
        "@angular-devkit/build-angular": "~0.6.8",
         "@angular/cli": "~6.0.8",
         "@angular/compiler-cli": "^6.0.3",
          "@angular/language-service": "^6.0.3",
           "@types/jasmine": "~2.8.6",
           "@types/jasminewd2": "~2.0.3",
            "@types/node": "~8.9.4",
             "codelyzer": "~4.2.1",
              "jasmine-core": "~2.99.1",
               "jasmine-spec-reporter": "~4.2.1",
                "karma": "^4.0.0",
                 "karma-chrome-launcher": "~2.2.0",
                  "karma-coverage-istanbul-reporter": "~2.0.0",
                   "karma-jasmine": "~1.1.1",
                 "karma-jasmine-html-reporter": "^0.2.2",
                 "protractor": "^5.4.2",
                  "ts-node": "~5.0.1",
                  "tslint": "~5.9.1",
                "typescript": "~2.7.2"
                 }
               }

回答1:

I had the same issue. I investigated that rxjs released a new version: 6.4.0. And it broke the build. According to review, the minimum supported version of TypeScript is 2.8. If you don't want to update TypeScript version, just change "rxjs": "^6.0.0", to "rxjs": "6.3.3" in package.json.



回答2:

Just remove ^ character from "rxjs": "^6.0.0" from package.json file and make it "rxjs": "6.0.0". It should work fine.



回答3:

I was facing the same issue while developing an angular6 project. I spent more time finally it's working for me.

Here is the solution:

  1. Open "package.json"

  2. rxjs and "TypeScript" verstion like below screenshot

  3. Change like the below screenshot:

  4. Next go to your project folder and delete "node_modules" folder.

  5. After delete, next run npm install in your project folder

  6. Finally run ng serve. It should work (I tried 3 projects and confirmed).



回答4:

Today I faced the same issue. None of the above answers worked except a comment from one @Nasreen Ustad. So what you have to do is:

  1. Go to package.json and modify "rxjs": "^6.0.0" to "rxjs": "6.0.0"
  2. Run npm update in your project

No need to change typescript version.(Mine: "typescript": "~2.7.2")



回答5:

Step 1 : Go to package.json and modify "rxjs": "^6.0.0" to "rxjs": "6.0.0"

Step 2 Run npm update in your project.



回答6:

Go to the project directory run: npm install rxjs@6.0.0 --save



回答7:

In your Package.json file remove ^ symbol (caret) from "rxjs": "^6.0.0" and add "rxjs": "6.0.0" it will work fine.



回答8:

Just change the TypeScript dependency version to ^2.8



回答9:

Seems like your Angular and/or rxjs version is not compatible with TypeScript.

Remove the ~ sign in the TypeScript version, add ^ instead. Then, install packages again.

Try running npm start and ng build prior to ng serve.



回答10:

Your package.json has following lines:

"rxjs": "^6.0.0",

"typescript": "~2.7.2"

This tells npm to install the following versions

rxjs: Latest version in version 6 series which is 6.4.0

typescript: Latest patched version in minor version 2.7 which is 2.7.2

Now RxJS module also installs the type definition files for TypeScript. The type definition file included in the rxjs module that got installed in your project is not compatible with typescript version installed in the same project.

So as a solution in your package.json file you can either bump up the version of Typescript to say 2.8 as

typescript: ^2.8.0

or bump down the version of ngrx to something like

ngrx: ~6.0.0 and

do a fresh npm install.

You can check the version number of the module installed by looking in following files:

node_modules/rxjs/package.json and
node_modules/typescript/package.json 


回答11:

Update in package.json rxjs": "6.3.3"

in terminal 1. run npm update 2. run ng serve

It should compile successfully



回答12:

Check your typescript version with below command.

~ tsc --version Version 3.3.3

As this is the latest typescript version, I've upgraded the project angular version to 7 by running below command in project home folder. It solved the issue.

~]# ng update @angular/cli @angular/core



回答13:

I have tried all the other answers. But I found issue. I had ts lint plugin installed which forced file to be ended without space. I removed it and it is working.

You can also remove the space going to that specific file.



回答14:

These two changes what you want:

// in package.json:

"rxjs": "^6.2.2" ==> "rxjs": "latest"
"typescript": "2.7.2" ==> "typescript": "2.8"

where ==> means to replace



回答15:

You can update your npm version to the latest, if it isn't, with:

npm update -g


回答16:

Encountered this error with: rxjs/store: ^6.4.0 typescript: ~2.7.2 angular/cli ~6.0.0

Updated everything to the latest except rxjs rxjs/store: ^6.3.3 typescript: ~3.1.1 angular/cli ~7.0.3

Basically I created an blank new project (ng new newProject) and installed @ngrx/store which brought down v6.3.3. This worked for me.



回答17:

I had to uninstall and reinstall angular CLI.

npm uninstall -g @angular/cli angular-cli
npm cache clean
npm install -g @angular/cli@latest
npm install -g @angular/cli@latest


回答18:

I changed the version for rxjs and typescript. My package.json has the following entries:

"typescript": "^2.7.2"
"rxjs": "^6.3.3",

I also had to upgrade angular cli.