10

I am using the observable object in an Angular 5 project of mine - up until a week or so ago it was running fine, now all of a sudden I'm getting the following error:

ERROR in node_modules/rxjs/Observable.d.ts(20,31): error TS1183: An implementation cannot be declared in ambient contexts.

I'm a bit of a newbie with Angular so any help would be much appreciated. Thanks!

chr15r
  • 569
  • 1
  • 5
  • 8
  • possible duplicate of https://stackoverflow.com/questions/37448491/angular-2-typescript-an-implementation-cannot-be-declared-in-ambient-contexts – Ragavan Rajan Feb 21 '18 at 00:01
  • @RagavanRajan I don't think it's a duplicate of that, because the error get's thrown by rxJS and this file is a declaration file. – masterfloda Feb 21 '18 at 00:15
  • @chr15r please show us some context. How did you import `Observable` and how did you use it? – masterfloda Feb 21 '18 at 00:16
  • Same Error: ERROR in node_modules/rxjs/internal/Observable.d.ts(14,29): error TS1183: An implementation cannot be declared in ambient contexts. The entire Observable.d.ts file is: export * from 'rxjs-compat/Observer'; This gives this error in Visual Studio Code: [ts] Cannot find module 'rxjs-compat/Observer'.,, This is a brand new project with a brand new NODE.js V8.11.2 just pulled down yesterday. NPN - V -5.6.0 – Aggie Jon of 87 Jun 01 '18 at 00:48

4 Answers4

8

In Angular 6 my Observables worked, but a "ng build --prod" gave the TS1183 error. My solution was:

npm install rxjs

Rob Lassche
  • 841
  • 10
  • 16
1

I tried reinstalling "rxjs" with the following command:

npm install rxjs

This didn't solved my problem.

The only thing that worked for me it was:

Replacing node_module folder with a new one

You can get it from new project or even delete and recreated it by executing:

npm install

Note: I would suggest to take it from new created project, for some reason this command do not work sometimes.

Avjol Sakaj
  • 1,281
  • 10
  • 14
0

npm install typescript@'>=2.7.0 <2.8.0

Eilt
  • 17
  • 2
  • 1
    updating typeScript version causes a new error ERROR in The Angular Compiler requires TypeScript >=3.1.1 and <3.3.0 but 3.3.3333 was found instead. – Ramin Ahmadi Mar 04 '19 at 22:47
0

For me, the problem was my old angular-cli version :

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

    and this one is to update your local project version:

  • rm -rf node_modules

  • npm uninstall --save-dev @angular/cli@latest
  • npm install

You might also need to install rxjs-compat(to make your old code to work). The new RxJS 6 is a bit different.