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

mongodb-stitch-browser-sdk - includes node-fetch lib #207

Closed
MichaelFBA opened this issue Jan 29, 2019 · 7 comments
Closed

mongodb-stitch-browser-sdk - includes node-fetch lib #207

MichaelFBA opened this issue Jan 29, 2019 · 7 comments

Comments

@MichaelFBA
Copy link

Hello,

I am trying to integrate the mongodb-stitch-browser-sdk into a nativescript vue app.

I am using es imports import { Stitch, AnonymousCredential } from 'mongodb-stitch-browser-sdk'; to start building the app and it is throwing an error which looks to be related to the sdk bundling in node-fetch (A node package inside of a browser sdk)

Here is a stacktrace

@file:///app/vendor.js:182:14
2   ../node_modules/assert/assert.js@file:///app/vendor.js:490:34
3   __webpack_require__@file:///app/bundle.js:76:34
4   @file:///app/vendor.js:626:33
5   ../node_modules/browserify-zlib/lib/binding.js@file:///app/vendor.js:1040:34
6   __webpack_require__@file:///app/bundle.js:76:34
7   @file:///app/vendor.js:1054:34
8   ../node_modules/browserify-zlib/lib/index.js@file:///app/vendor.js:1666:34
9   __webpack_require__@file:///app/bundle.js:76:34
10  @file:///app/vendor.js:32994:33
11  ../node_modules/node-fetch/lib/index.es.js@file:///app/vendor.js:33190:34
12  __webpack_require__@file:///app/bundle.js:76:34
13  ../node_modules/cross-fetch/dist/node-ponyfill.js@file:///app/vendor.js:8598:36
14  __webpack_require__@file:///app/bundle.js:76:34
15  ../node_modules/mongodb-stitch-core-sdk/dist/esm/internal/net/FetchTransport.js@file:///app/vendor.js:16222:88
16  __webpack_require__@file:///app/bundle.js:76:34
17  ../node_modules/mongodb-stitch-core-sdk/dist/esm/index.js<…>
JavaScript error:
file:///app/vendor.js:182:14: JS ERROR TypeError: util.inherits is not a function. (In 'util.inherits(assert.AssertionError, Error)', 'util.inherits' is an instance of Object)
(CoreFoundation) *** Terminating app due to uncaught exception 'NativeScript encountered a fatal error: TypeError: util.inherits is not a function. (In 'util.inherits(assert.AssertionError, Error)', 'util.inherits' is an instance of Object)
at
@adamchel
Copy link
Contributor

Hi @MichaelFBA

Thanks for reporting this issue. This issue is due to the fact that we use the cross-fetch polyfill for fetch in the core module shared by all of our JavaScript SDKs. cross-fetch is intended to be a universal JavaScript polyfill for fetch that fills in the correct polyfill in each environment, but for some reason, the NativeScript bundler is trying to bundle the node-fetch dependency of cross-fetch even though it wouldn't be used at runtime.

I would recommend opening an issue at https://github.com/lquixada/cross-fetch referencing this issue and letting them know cross-fetch doesn't work with NativeScript, but in the meantime, we'll look into a workaround where instead of using a fetch polyfill at all in our core module, we'll only use the appropriate polyfill on each platform.

I'll try to update you soon, but let us know if you have any further issues!

@MichaelFBA
Copy link
Author

Many Thanks @adamchel

I'll do as you mentioned. Looking forward to using it :) 👍

@adamchel
Copy link
Contributor

We've just released version 4.3.0, which removes cross-fetch as a dependency of the browser SDK, and just uses the whatwg-fetch polyfill.

Let us know if this updated version works for you!

@tkaye407
Copy link
Contributor

tkaye407 commented Mar 8, 2019

Hi @MichaelFBA. We haven't heard back from you and believe that your issue has been resolved, so we will be closing this ticket.

@conor909
Copy link

conor909 commented May 12, 2019

searchParams: 'URLSearchParams' in self,
ReferenceError: self is not defined

I'm getting this on the latest browser sdk (^4.3.1)

@fabien-h
Copy link

fabien-h commented Jul 18, 2019

Same error here

ReferenceError: self is not defined at /Volumes/Projects/------/node_modules/whatwg-fetch/dist/fetch.umd.js:8:40 at /Volumes/Projects/------/node_modules/whatwg-fetch/dist/fetch.umd.js:2:66 at Object.<anonymous> (/Volumes/Projects/------/node_modules/whatwg-fetch/dist/fetch.umd.js:5:2) at Module._compile (internal/modules/cjs/loader.js:776:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10) at Module.load (internal/modules/cjs/loader.js:643:32) at Function.Module._load (internal/modules/cjs/loader.js:556:12) at Module.require (internal/modules/cjs/loader.js:683:19) at require (internal/modules/cjs/helpers.js:16:16) at Object.<anonymous> (/Volumes/Projects/------/node_modules/mongodb-stitch-browser-core/dist/cjs/core/internal/net/BrowserFetchTransport.js:4:22) at Module._compile (internal/modules/cjs/loader.js:776:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10) at Module.load (internal/modules/cjs/loader.js:643:32) at Function.Module._load (internal/modules/cjs/loader.js:556:12) at Module.require (internal/modules/cjs/loader.js:683:19) at require (internal/modules/cjs/helpers.js:16:16)

I cannot start to try :(

Would it be possible to send requests without an SDK ? Just a basic REST API.

@zenati
Copy link

zenati commented May 30, 2020

Same here, same error. Why is this issue closed?

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

6 participants