rxjs: TypeError: Observable.of is not a function since rxjs 6.3.0
After updating rxjs from version 6.2.x
to version 6.3.0
, the following:
import 'rxjs/add/observable/of';
// or
import { Observable } from 'rxjs/Observable';
Observable.of(...)
Are not working anymore. The only way to make it work now is by using:
import { of } from 'rxjs/observable/of';
of(...)
is this a bug or the intended behaviour? It looks a breaking change to me š¦
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 30
- Comments: 56 (8 by maintainers)
Commits related to this issue
- fix(rxjs-compat): downgrade to 6.2.2 https://github.com/ReactiveX/rxjs/issues/4070 — committed to corinnekrych/fabric8-ui by corinnekrych 6 years ago
- fix(rxjs-compat): downgrade to 6.2.2 https://github.com/ReactiveX/rxjs/issues/4070 (#3333) — committed to fabric8-ui/fabric8-ui by corinnekrych 6 years ago
- fix(rxjs-compat): downgrade to 6.2.2 https://github.com/ReactiveX/rxjs/issues/4070 (#3333) — committed to fabric8-ui/fabric8-ui by corinnekrych 6 years ago
- fix(rxjs-compat): downgrade to 6.2.2 https://github.com/ReactiveX/rxjs/issues/4070 (#3333) — committed to fabric8-ui/fabric8-ui by corinnekrych 6 years ago
- fix(rxjs-compat): downgrade to 6.2.2 https://github.com/ReactiveX/rxjs/issues/4070 (#3333) — committed to fabric8-ui/fabric8-ui by corinnekrych 6 years ago
- Update fabric8-ui.yaml * f65e037c2 style(lint): add airbnb rule overrides * 915a75bc4 feat(angular): add angular support to scripts * ac48d5b9f fix(header): fix capitalization of 'Create Space' in ... — committed to openshiftio/saas-openshiftio by joshuawilson 6 years ago
- Update fabric8-ui.yaml (#1099) * f65e037c2 style(lint): add airbnb rule overrides * 915a75bc4 feat(angular): add angular support to scripts * ac48d5b9f fix(header): fix capitalization of 'Create Sp... — committed to openshiftio/saas-openshiftio by joshuawilson 6 years ago
- fix(compat): remove internal from import locations Closes #4070 — committed to cartant/rxjs by cartant 5 years ago
This is what I did:
ng update
ng update @angular/core -> reiterate with the different modules that the previous command shows
npm update --save (in order to update the modules which are not managed through ng update)
npm list rxjs (in order to see the rxjs dependencies, you should have rxjs 6.3.2 on all core modules and this is what we expect to change)
npm un --save rxjs
npm un --save rxjs-compat
npm list --depth=0 (in order to check that rxjs is removed, you should have a warning or an error at the end of the list)
npm i --save rxjs@6.2.2
npm i --save rxjs-compat@6.2.2
npm list rxjs (check that the previous dependencies have been changed with 6.2.2)
Thatās all for me. Of course, if you perform a
and then a
==> you will reinstall rxjs 6.3.2 due to the angular current dependenciesā¦
Force or reinstall exact version of
rxjs@6.2.2
andrxjs-compat@6.2.2
.We also hit that issue this afternoon when some coworker restarted their node_modules from scratch. Setting the version in
package.json
to force the usage of6.2.2
fixed the issue. Unfortunately, we cannot drop usage ofrxjs-compat
package because we have external dependencies relying on it. otherwise, it would have fixed the issue. So basically anybody hitting this have 2 options :6.2.2
rxjs-compat
and do the full migration to6.x.y
according you donāt have any external dependencies that rely on it by following this page: https://rxjs-dev.firebaseapp.com/guide/v6/migrationimport
Observable
fromrxjs
instead ofrxjs/Observable
. Also for static methods likeof
,zip
, import static function fromrxjs
with the method name. Itās more like rxjs-6 way.ā
import { Observable } from 'rxjs';
āimport { zip } from 'rxjs';
āimport { zip as observableZip } from 'rxjs';
āimport { Observable } from 'rxjs/Observable';
Analysis of Cause
Angular-cli uses a resolve alias for module
rxjs/Observable
internally while building, mapping it torxjs-compat/_esm5/Observable
. This mapping is provided by rxjs itself. see Build and Treeshaking for more information. Find angular-cli including the path-mapping here.Prior to v6.3.0,
rxjs-compact/_esm5/Observable
exportsObservable
fromrxjs
, and when webpack resolvesrxjs
, it takes the value of keymodule
in rxjsāpackage.json
as entry point. See resolve.mainFields for more information. For v6.2.2 themodule
value isrxjs/_esm5/index.js
, so the exportedObservable
object is fromrxjs/_esm5/index.js
. But, released in v6.3.0, commit https://github.com/reactivex/rxjs/commit/3f75564 changed the import path ofObservable
fromrxjs
torxjs/internal/Observable
, causing webpack not to honor themodule
value inpackage.json
anymore and directly importObservable
fromrxjs/internal/Observable
. The correct resolved path should berxjs/_esm5/internal/Observable
.Possible solutions for
rxjs
project itself, would be to addrxjs/internal/Observable
to its path-mapping file, mapping it torxjs/_esm5/internal/Observable
, or revert https://github.com/reactivex/rxjs/commit/3f75564 . For users please consider migrate your pre-rxjs6 code to latest. For angular users, if you insist, I have a workaround for you. Add the following snippet to yoursrc/tsconfig.app.json
:Please remove this workaround after you finish rxjs 6 migration on your project. It may not work for future versions.
@benlesh: Minimal reproduction:
with angular cli 6.2.4
@angular-devkit/build-angular@0.8.1
did not fix the issue for me. Also tried0.8.3
Thepackage.json
"resolutions": { "**/rxjs": "6.3.2" }
trick did not seem to change the resolved rxjs transitive versions inpackage-lock.json
Many sub-dependencies still use"rxjs": "~6.2.0"
So downgrading to
rxjs@6.2.2
is the only solution that works for me.Sidenote:
ng update @angular/core
does bump RxJS to 6.3.2 So IMO this issue is fairly important to fixFixed by enforcing 6.3.2 for all dependencies.
Add to package.json
Agreed. Full migration would be the answer⦠but since weāre just making the upgrade to latest Angular v6 and getting everything working (including fixing unit tests that are breaking after the update), adding that just yet isnāt in the cards.
But isnāt the fact that weāre using rxjs-compat mean that we donāt have to change our imports (as in the sample in the original issue description)? I shouldnāt have to change all the imports until we migrate and donāt need rxjs-compat (?)
Import : import { of as observableOf} from ārxjsā;
and Change Observable.of to observableOf
Instead of import ārxjs/add/observable/ofā;
Below works for me import { of } from ārxjsā;
This one is worked for me as well. Thanks š :
Please find sample code here: https://github.com/s25g5d4/rxjs-path-mapping-issue
@benlesh And the reason has to do with this change:https://github.com/ReactiveX/rxjs/commit/3f755640ab0214d17cb16318fdd29a3a35ff8093
rxjs-compat 6.2.2
Observable.js
add/observable/of.js
rxjs-compat 6.3.3
Observable.js
add/observable/of.js
add/observable.of.js is the same as in 6.2.2. So there is a mismatch in 6.3.3 the of is not applied to the Observable imported in typscript with
import {Observable} from "rxjs/Observable";
I do not know enough about this solution to know why this is, since the observable exported from Observable.js is also the āinternalā oneā¦
I encountered this issue while migrating an application from angular 4 to angular 6. Iām still in the process of weeding out other issues but so far I have resolved this one in my
package.json
(I may encounter a different solution and submit a newer solution in the future):Both of these works
Iāve updated @angular-devkit from 0.7.5 to 0.8.1 and it solved the problem, with the command
npm install --save-dev @angular-devkit/build-angular@0.8.1
I have the same error but only during running ng build ui-components which is my library project stored in projects folder. Running ng build --prod for a application itself works good.
Some ideas?, yesterday it was working, today I run
rm -rf node_modules yarn.lock &&Ā yarn install
and i have this.@anandvr27 I cannot provide you more unfortunately. Try first to remove
rxjs
, perform anpm list --depth=0
in order to check thatrxjs
is not installed and then reinstall the 6.2.2 version. You should do the same withrxjs-compat
if youāre migrating. I donāt userxjs-compat
anymore.@skonx i followed the steps given by you, but its not updated to 6.2.2 in all levels. npm list rxjs shows ±- @angular-devkit/build-angular@0.6.8 | ±- @angular-devkit/architect@0.6.8 | |
-- rxjs@6.2.0 | +-- @angular-devkit/core@0.6.8 | |
ā rxjs@6.2.0 |-- rxjs@6.2.0 +-- @angular/cli@6.1.5 | +-- @angular-devkit/architect@0.7.5 | |
ā rxjs@6.3.2 deduped | ±- @angular-devkit/core@0.7.5 | |-- rxjs@6.3.2 deduped | +-- @angular-devkit/schematics@0.7.5 | | +-- @angular-devkit/core@0.7.5 | | |
ā rxjs@6.3.2 deduped | |-- rxjs@6.3.2 | +-- @schematics/angular@0.7.5 | |
ā @angular-devkit/core@0.7.5 | |-- rxjs@6.3.2 | +-- @schematics/update@0.7.5 | | +-- @angular-devkit/core@0.7.5 | | |
ā rxjs@6.3.2 deduped | |-- rxjs@6.3.2 |
ā rxjs@6.3.2 `-- rxjs@6.2.2i tried clearing the npm cache and removing the nodemodules. Nothing worked. Can you please let me know how to reset this? thanks!
Yes. maybe not literally but Iāve tried: npm install --save rxjs/rxjs-compat@6.2.2 --force npm cache clean --force delete node_module and npm installā¦
I have tried several things, also reinstalling 6.3.2ā¦maybe I have not done something completely correctly, I am a beginner
Anyone tested this with rxjs/rxjs-compat 6.3.1?
for me switching back to
6.2.1
solves the issue