8

I have an Angular 5 project which has many modules and hundreds of components. Since RxJs 6 you have to use

someObservable.pipe(map(...))

instead of

someObservable.map(...)

I want to migrate this project from Angular 5 to 6, but dont want to change every occurrence of .map() by hand.

The Angular update side suggests

rxjs-5-to-6-migrate -p src/tsconfig.app.json

for migrating to rxjs 6, but I am afraid that this can't change my code.

Any suggestions on how to save time and change from .map() to .pipe(map()) automatically?

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
lynxSven
  • 555
  • 1
  • 10
  • 27
  • 1
    Are you sure the migration command doesn't work for you? I tried it in one of my projects and it did a solid job. The obvious workaround would be to do a find and replace yourself. – enf0rcer May 11 '18 at 12:44
  • @enf0rcer If I rerun the command: 'Cannot find any possible migrations'. Did the migrationtool change your code to the new layout? Would be a good clue if the tool is actually capable to do that. – lynxSven May 11 '18 at 12:46
  • Yes it did, I'm not sure about the map method though. But it surely changed imports and stuff like that. – enf0rcer May 11 '18 at 12:49
  • It did change my imports successfully. It has not changed any of the .map functions around – lynxSven May 11 '18 at 12:51
  • Maybe your code is too complex for the script to automatically change them. My project was already using the pipe pattern. So it did not change those. It only changed. the old import paths to the new ones. – enf0rcer May 11 '18 at 12:52
  • Or the script just doesn't have the functionality, thats possible as well afcourse. – enf0rcer May 11 '18 at 12:52
  • 2
    I checked it for you, the GitHub page mentions it is able to help you out "to some extent": https://github.com/ReactiveX/rxjs/blob/master/MIGRATION.md – enf0rcer May 11 '18 at 12:54
  • Yeah, I ran into the same problem too and couldn't figure out a solution besides manual editing (I don't even know where I would start for a find-and-replace...). I really wish they had made the pipe syntax optional; I get that it's useful in some cases but for my project all it did was make the code uglier and the migration ten times more complicated. – John Montgomery Jun 13 '18 at 22:04
  • 1
    @David Bulté's answer should work, but first you have to revert changes made with initial running of the command. I needed to do the same and it worked for me perfectly. – Konto Jul 12 '18 at 21:12
  • @Konto I tried different approaches now. Clone my repository again and trying to use David Bulté's answer. The migration always runs through with the same result. Imports are altered, but map are not changed. – lynxSven Sep 14 '18 at 08:15

1 Answers1

5

Maybe this can help?

I followed all steps in https://update.angular.io/, but somehow at the end of chain I had the same problem you have: all my rxjs imports were changed, but the operators hadn't been changed to pipeable operators.

Then I noticed that the rxjs-compat package hadn't been installed (due to https://github.com/angular/angular-cli/issues/10631?). After installing rxjs-compat manually (npm install rxjs-compat --save) and running rxjs-5-to-6-migrate -p src/tsconfig.app.json again, the pipes appeared!

David Bulté
  • 2,988
  • 3
  • 31
  • 43
  • 2
    Hmm no doesn't work for me. My map function still stay the same. The command executes and returns "Cannot find any possible migrations" – lynxSven Jun 15 '18 at 11:58