Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find module 'forcejs'. while using angular 2 in ionic 2 #12

Open
KaushikRay opened this issue Jul 10, 2016 · 3 comments
Open

Cannot find module 'forcejs'. while using angular 2 in ionic 2 #12

KaushikRay opened this issue Jul 10, 2016 · 3 comments

Comments

@KaushikRay
Copy link

I am working as a noob on my ionic 2 / ang 2 application. I am trying to set it up to use forcejs auth implementation.

Now I create a basic app following the ionic 2 tutorial here - http://ionicframework.com/docs/v2/getting-started/tutorial/

Now I am trying to integrate my force js implementation based on - http://coenraets.org/blog/2015/10/integrating-ecmascript-6-web-applications-with-salesforce-using-oauth-and-rest/

Now on app initialization I want to login using SF dev creds and Oauth.

I did a forcejs install using

npm install forcejs --save-dev

And in my app.ts file I am trying to import same. App.ts -

import {Component, ViewChild} from '@angular/core';
import {ionicBootstrap, Platform, MenuController, Nav} from 'ionic-angular';
import {StatusBar} from 'ionic-native';
import {HelloIonicPage} from './pages/hello-ionic/hello-ionic';
import {ListPage} from './pages/list/list';

//ERROR on this line - TypeScript error: app/app.ts(7,24): Error TS2307: Cannot find module 'forcejs'
// wbile doing a gulp build
import * as force from 'forcejs';


@Component({
  templateUrl: 'build/app.html'
})
class MyApp {
  @ViewChild(Nav) nav: Nav;

  // make HelloIonicPage the root (or first) page
  rootPage: any = HelloIonicPage;
  pages: Array<{title: string, component: any}>;

  constructor(
    private platform: Platform,
    private menu: MenuController
  ) {
    this.initializeApp();

    // set our app's pages
    this.pages = [
      { title: 'Hello Ionic', component: HelloIonicPage },
      { title: 'My First List', component: ListPage }
    ];
  }

  initializeApp() {
    this.platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.

      // Login in Salesforce using forcejs
      force.init({
          proxyURL: "https://dev-cors-proxy.herokuapp.com/"
      });

      force.login().then(() => {
          console.log("logged in");
      });

      StatusBar.styleDefault();
    });
  }

  openPage(page) {
    // close the menu when clicking a link from the menu
    this.menu.close();
    // navigate to the new page if it is not the current page
    this.nav.setRoot(page.component);
  }
}

ionicBootstrap(MyApp);

Now check top of the page for imports

TypeScript error: app/app.ts(7,24): Error TS2307: Cannot find module
'forcejs'

I can see forcejs under node_modules folder but not sure now how to import same.

Please help with same.

@karthikkornalies
Copy link

Hello Kaushik, Just wondering if you had chance to fix this issue. I am facing a similar issue on my Ionic2 app. Would appreciate if you shed any lights on this.

@smukov
Copy link

smukov commented Sep 13, 2016

I solved this issue by copying the force.js and pasting it in app folder, next to app.ts. I also renamed the force.js to force.ts. Then I could reference it in app.ts like this:

import * as force from './force';

@fishme
Copy link
Contributor

fishme commented Feb 22, 2017

with the current version it works also with:
import { OAuth, DataService } from 'forcejs';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants