Import { resolve } from 'path' not working - Ionic V4

Hello,

i try to chain promises so i get rid of nesting promises in promises…

It is an Ionic Angular project.

i would like to work with ‘resolve’ and ‘reject’, but i cannot import it. This is my code in home.page.ts:

import { Component, OnInit } from '@angular/core';
import { resolve } from 'path';
import { reject } from 'q';

export class HomePage implements OnInit {

   ngOnInit() {

       this.nativeStorage.getItem("something").then(
      success => {

        resolve("ok");

      },

      error => {

        reject("error");

      }
    ).then(
      success => {

        console.log(success);

      }, error => {

        console.log(error);

      }
    ) //continue with chain here

   }

}

I do get the error on compiling, that

ERROR in src/app/home/home.page.ts:4:25 - error TS2307: Cannot find module 'path'.
4 import { resolve } from 'path';
                                      ~~~~~~
[ERROR] An error occurred while running subprocess ng.
        ng run app:ionic-cordova-build --platform=android exited with exit code 1.
        Re-running this command with the --verbose flag may provide more information.

Thanks in advance, Louis

This is a good idea.

This, however, isn’t, so…

Don’t. Reverse course. Take all that out.

This is probably also not a great idea, but I can’t say for certain because we aren’t shown what this.nativeStorage is. If it’s this ionic-native thingy, then I would move all interaction with it out of pages and into a service. This will isolate it and allow for more flexibility in the future. In any event, the only thing you should be doing with Promises in this context is chaining then clauses off of them.

Which leads me back to the beginning. Can you instead post the “before” version of this code, containing the “nesting promises in promises” you’re concerned about? I think it’s going to be easier to fix that than what we have here.