question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RxJS v6/7 support in Angular v13 breaking imports

See original GitHub issue

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

According to angular/angular-cli#21795:

With the Angular framework supporting rxjs 7 for Angular 13, new projects (ng new …) can now be created using rxjs 7. rxjs 6 is also still fully supported with Angular 13 allowing existing projects to continue to use rxjs 6 if preferred or required. Support for rxjs 7 within the framework was enabled via #42991

While supporting multiple versions of such direct dependencies can seem to be nice to final users, it can lead to a lot of problems and is not nice to library authors, as they must ensure compatibility with both versions.

For RxJS 7, there is a very important change in v7.2 (from RxJS changelog):

Operators are all exported at the top level, from “rxjs”. From here on out, we encourage top-level imports with RxJS. Importing from rxjs/operators will be deprecated soon

So it means that if a library author uses RxJS 7.2 new imports (for example import { mapTo } from 'rxjs';), then if the lib is used in a user application still with RxJS 6, the compilation will break (error below).

You can reproduce with these steps:

  1. git clone https://github.com/cyrilletuzi/ng13-rxjsversionsissue
  2. cd ng13-rxjsversionsissue
  3. npm install
  4. npm start (builds the lib with RxJS 7 then the app with RxJS 6)

The project was just generated with Angular CLI v13 and a library was generated with ng g library demo.

It may not be the only issue (issues already happened in the past where some RxJS classes like Observable were incompatible between different versions).

Also, while I’m not sure, for the opposite scenario, it may lead to performance/bundle size issue. If a user application uses RxJS 7 new imports, and libs are still using RxJS 6 imports (which seems to be the case of Angular itself), won’t it mean that operators will be included twice in the final bundle?

Please provide a link to a minimal reproduction of the bug

https://github.com/cyrilletuzi/ng13-rxjsversionsissue

Please provide the exception or error you saw

./dist/demo/fesm2015/demo.js:9:28-33 - Error: export 'mapTo' (imported as 'mapTo') was not found in 'rxjs'


### Please provide the environment you discovered this bug in

```true
Angular CLI: 13.0.0-next.7
Node: 16.10.0 (Unsupported)
Package Manager: npm 7.24.1
OS: darwin arm64

Angular: 13.0.0-next.9
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1300.0-next.7
@angular-devkit/build-angular   13.0.0-next.7
@angular-devkit/core            13.0.0-next.7
@angular-devkit/schematics      13.0.0-next.7
@angular/cli                    13.0.0-next.7
@schematics/angular             13.0.0-next.7
ng-packagr                      13.0.0-next.5
rxjs                            6.6.7
typescript                      4.4.3

Anything else?

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
alan-agius4commented, Oct 1, 2021

Regarding your concern of increase in bundle size. This shouldn’t be a problem at all, because the operators imported directly from rxjs are just a reexport from rxjs/operators, and therefore they are the same symbols.

https://github.com/ReactiveX/rxjs/blob/e57473574a0e4661e7d526db5e261a62f6602d56/src/index.ts#L146

1reaction
cyrilletuzicommented, Oct 1, 2021

@alan-agius4 Oops, fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular v13 is now Available
We're back with the brand new release of Angular v13 to share with all of ... We've also updated the APF to support...
Read more >
Breaking Changes in Version 7 - RxJS
To workaround this issue there are two things you can do: 1. Rewrite your operators as outlined in the documentation, such that they...
Read more >
What's new in Angular v13! - Nx Blog
Angular 13 now comes with support for Typescript 4.4.2. Older versions are no longer supported. Make sure to have a look at the...
Read more >
v13 · Issue #715 · angular-eslint/angular-eslint - GitHub
ESLint 8 had breaking changes for plugin maintainers, and that is the version of eslint-plugin-import which supports ESLint 8. Getting this error. npx...
Read more >
Fix your RxJS 6 Imports & Operators - What's New in RxJS 6?
RxJS 6 was released and unlike older RxJS versions, it requires you to adjust your code. The import paths changed due to internal...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found