Start a new topic

Can we use npm package kinvey-html5-sdk in the browser?

The Guide directs us to use the global script from your CDN. However I see the SDK is available in npm and I would MUCH rather use this. The API reference is also written in terms of ES6 modules. The GitHub project also appears to generate the modular version as well as the script

Is the npm module supported or not?

* Global scripts are a last resort these days in modular development, for well documented reasons.

* The global script is large and using modules should reduce script size (though this is topic in it's own right [1])

However in a quick test I was unable to get the modules to work.

* I change the import from ```import {Kinvey} from 'kinvey'``` given in the reference to import ```Kinvey from 'kinvey-html5-sdk'``` as Kinvey is the default export and not also a named export The module name change is obviously for v3.0.0.

* I got the following error, and looking at the source the symbol is not defined. Perhaps relying on a import else where?

Running tests in electron

ReferenceError: regeneratorRuntime is not defined

   at node_modules/kinvey-javascript-sdk-core/es5/rack/middleware.js:38:1

   at node_modules/kinvey-javascript-sdk-core/es5/rack/middleware.js:66:1

   at Object.73../asciiTree (node_modules/kinvey-javascript-sdk-core/es5/rack/middleware.js:88:1)

   at s (node_modules/browser-pack/_prelude.js:1:1)

   at node_modules/browser-pack/_prelude.js:1:1

   at Object.82../middleware (node_modules/kinvey-javascript-sdk-core/es5/rack/rack.js:12:1)

   at s (node_modules/browser-pack/_prelude.js:1:1)

   at node_modules/browser-pack/_prelude.js:1:1

   at Object.<anonymous> (node_modules/kinvey-javascript-sdk-core/es5/requests/request.js:14:1)

   at Object.86.../client (node_modules/kinvey-javascript-sdk-core/es5/requests/request.js:988:1)

1: I see you use rxJS 5 which could be shared between Kinvey and app (until I change to xstream). Also my app is transpiled from ES6 to ES5 which probably means the various ES6 modules and Promise implementation aren't needed. 

OK it's not clear if the npm package is designed to run in Node, browsers or both?

Update: by deleting node_modules and installing I find the npm package(s) works fine.

However, the import statements given in the API reference are incorrerect

import {Kinvey} from 'kinvey' -> import Kinvey from 'kinvey-html5-sdk'

import {User} from 'kinvey/src/core/user.js' -> import {User} from 'kinvey-javascript-sdk-core/es5/user.js'

I can't believe the npm package(s) is not supported by you so will switch to using it for now.

Please ignore my last comment - I CANNOT use the npm package due to the regenerator problem

I inadvertently included the global script as well as importing the modules - doh!

Please advise as I'd like to use the modules

Oh, I just wondered if 'regenerator ' is  a peer dependency?

That does seem unlikely as RxJS is not.

Login or Signup to post a comment