Karteek Karteek - 10 months ago 244
Javascript Question

Installing JavaScript AWS SDK for NativeScript

I'm trying to use AWS-SNS in NativeScript. AWS SDK is available for JavaScript.Can anybody know how to install AWS SDK for NativeScript.

I tried by installing aws-sdk for javascript on Node.js. Reference link is "https://www.npmjs.com/package/aws-sdk".
But because of below code


In Nativescript an error saying Failed to find module: "crypto" is coming.With a bit of search in internet, I found that crypto module support is not added in Nativescript.

Now I'm wondering are there any other ways.

Thanks In Advance.

Answer Source

As NativeScript does not (yet) "polyfill" a crypto module this could be a hard thing.

Searching the code for references to crypto, you'll find that there's not that many uses and the uses are not that advanced. What this means is that you should be able to substitute the Node module crypto with crypto-js which works in a NativeScript environment.

You might need to fork the AWS SDK codebase and substitute the calls to the Node crypto module with calls to the corresponding methods in crypto-js. Unfortunately they do not share the same API.

If you're running Webpack (or anything like it) you should be able to create a "transformer module" which will transform Node crypto calls to the corresponding crypto-js calls and then make sure your transformer module is called instead of the Node crypto module via Webpack alias'.