3

When using to angular 6 and swagger codegen, i'm getting typescript compiler errors related to rxjs:

Cannot find module 'rxjs-compat/Observable'

I found the following https://github.com/ReactiveX/rxjs/blob/master/MIGRATION.md#rxjs-v5x-to-v6-update-guide

I'm using swagger-codegen: stable 2.3.1 on a mac (installed with brew).

I appreciate any guidance.

Update -----------------------

I added rxjs-compat to my angular6 project using

npm install --save-dev rxjs-compat

I now get compiler warnings, but the compiler errors are gone and the project seems to run

Datum Geek
  • 1,358
  • 18
  • 23

3 Answers3

3

If you are migrating from a previous angular version, follow the following guide:

https://update.angular.io/

The rxjs-compat package is to have compatibility with previous rxjs implementations. For example:

import { concat } from 'rxjs/observable/concat'

However, that should be updated to the new implementation that comes along version 6. For example:

import { catchError, map, switchMap } from 'rxjs/operators';

That said. You also have to change the implementation of your observable operators using pipe. For example:

this.sampleService
      .search(
        payload.firstName,
        payload.lastName,
        payload.dateOfBirth
      )
      .pipe(
        map(response => new sampleActions.SearchSuccess(response.json())),
        catchError(error => of(new sampleActions.SearchFail(error)))
      )

As you can see, the operators map and catchError have a different implementation, using the pipe operator.

Maybe you can share a copy of the logs, so it will be easier to understand what is causing errors/warns.

2

I was facing the same problem.

Even by replacing swagger generator with 2.4 didn't fix the issue, the workaround I found was to add rxjscompat to the project: npm install rxjs-compat@6

See more details on the discussion: https://github.com/swagger-api/swagger-codegen/issues/8179#issuecomment-402575414

hamilton.lima
  • 1,902
  • 18
  • 29
1

For me, I used the "swagger-codegen-cli-2.4.0.jar" to generate, and to solve the "rxjs" issues, I added this at the end of the command:

--additional-properties ngVersion=6
Henry
  • 631
  • 10
  • 21