Error TS1005: ';' expected. TypeScript Angular 6 For First Build error rxjs inside node_modules

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"
}
}
106052 次浏览

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.

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.

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

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

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.

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

    enter image description here

  3. Change like the below screenshot:

    enter image description here

  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).

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

npm update -g

Just change the TypeScript dependency version to ^2.8

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

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.

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

Update in package.json rxjs": "6.3.3"

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

It should compile successfully

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")

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

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.

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

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

Go to the project directory run:

npm install -s rxjs-compat

The below steps resolved my issue

There are two files that have to modify.

  • node_modules\@ag-grid-community\core\dist\cjs\utils\index.js

//export * from "./utils";

  • node_modules\@ag-grid-community\core\dist\cjs\utils\index.d.ts

//_export(require("./utils"));

comment utils as above. now npm start

My current project is in asp.net MVC with angular 8. After updating the angular project from 8 to 9, the angular build working fine but facing the above problem for MVC build. (on azure)

Just hiding the

node_modules

folder, solved my problem.

hide node_modules folder