Skip to content

Ionic Mobile Typescript issue with promise #124

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

Closed
phingers opened this issue Apr 1, 2018 · 5 comments
Closed

Ionic Mobile Typescript issue with promise #124

phingers opened this issue Apr 1, 2018 · 5 comments

Comments

@phingers
Copy link

phingers commented Apr 1, 2018

Cross-posting: ionic-team/ionic-framework#13459

I'm getting this error with the MongoDB Stitch service and trying to import their sample code into my Ionic Application.

import { StitchClientFactory } from 'mongodb-stitch';
let appId = 'myappid-from-mongodb';
    const clientPromise = StitchClientFactory.create(appId);
    clientPromise.then(client => {
      const db = client.service('mongodb', 'mongodb-atlas').db('myDBname');
      client.login().then(() =>
        db.collection('Messages').updateOne({owner_id: client.authedId()}, {$set:{number:42}}, {upsert:true})
      ).then(() =>
        db.collection('Messages').find({owner_id: client.authedId()}).limit(100).execute()
      ).then(docs => {
        console.log("Found docs", docs)
        console.log("[MongoDB Stitch] Connected to Stitch")
      }).catch(err => {
        console.error(err)
      });
    });
  }

Error is:

polyfills.js:3 Uncaught TypeError: t.resolve is not a function
at Object.setNativePromise (polyfills.js:3)
at L.configurable.L.set (polyfills.js:3)
at module.exports (bson.js:298)
at $export (bson.js:106)
at Object. (bson.js:11113)
at webpack_require (bson.js:30)
at Object. (bson.js:8511)
at webpack_require (bson.js:30)
at Object. (bson.js:8372)
at Object. (bson.js:8398)

I appreciate any work arounds or ideas on how to get this working for me in Ionic Mobile Hybrid Framework!

@edaniels
Copy link
Contributor

edaniels commented Apr 1, 2018

Hey @phingers, I'm taking a look into this now. Looks like it may just be a polyfill issue.

@edaniels
Copy link
Contributor

edaniels commented Apr 1, 2018

@phingers, I'm unable to determine the issue exactly but it appears zone.js is overriding the Promise that mongodb-stitch expects to use. I've seen reports of this issue before outside of the Stitch SDK so I'm not sure there's anything we can do to fix it.

This seems relevant however: angular/zone.js#891

@phingers
Copy link
Author

phingers commented Apr 1, 2018

I have it working in IONIC without the factory by importing

<script src="https://s3.amazonaws.com/stitch-sdks/js/library/stable/stitch.min.js"></script>

into index.html

Then in my TS files, I can do something similar too.

let client = new stitch.StitchClient(appId);

		let db = client.service("mongodb", "mongodb-atlas").db("DBNAMEHERE");
    client.login().then(() =>
        db.collection('Messages').updateOne({owner_id: client.authedId()}, {$set:{number:42}}, {upsert:true})
      ).then(() =>
        db.collection('Messages').find({owner_id: client.authedId()})
      ).then(docs => {
        console.log("Found docs", docs)
        console.log("[MongoDB Stitch] Connected to Stitch")
      }).catch(err => {
        console.error(err)
      });

Hope it helps someone else until it is patched properly.

@edaniels edaniels closed this as completed Apr 3, 2018
@girish-fuluskar
Copy link

Hi,

I am facing following issue.
Hope will get help.

My Use case:

Call javascript function from JS file (included in project) in ionic 4 on particular page

I having following issue.

ERROR TypeError: t.resolve is not a function
at Object.setNativePromise (polyfills.js:3)
at L.configurable.L.set (polyfills.js:3)
at n.exports (ocw.js:4850)
at a (ocw.js:4850)
at Object.209.100 (ocw.js:4851)
at s (ocw.js:4850)
at ocw.js:4850
at Object.327.131 (ocw.js:4852)
at s (ocw.js:4850)
at ocw.js:4850

Steps Followed:

  1. Included JS file under src/assets
  2. added reference in index.html
<script src="cordova.js"> </script> <script src="assets/ocw.js"></script>
  1. In desired file, declared variable as function name
  2. called javascript function under, ionViewDidLoad()

Ionic setup:

Ionic:

ionic (Ionic CLI) : 4.1.2 (/usr/local/lib/node_modules/ionic)
Ionic Framework : ionic-angular 3.9.2
@ionic/app-scripts : 3.2.0

Cordova:

cordova (Cordova CLI) : 8.0.0
Cordova Platforms : android 6.4.0, ios 4.5.5
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.2, cordova-plugin-ionic-webview 2.0.2, (and 9 other plugins)

System:

ios-deploy : 1.9.2
ios-sim : 6.0.0
NodeJS : v8.12.0 (/usr/local/bin/node)
npm : 6.4.1
OS : macOS
Xcode : Xcode 10.1 Build version 10B61

@MiguelGonzalezAravena
Copy link

@girish-fuluskar How did you resolve this? I'm facing the same issue.

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