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
require("aws-sdk")
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.
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'.
This is an old question, but I recently had to figure this out so for future AWS-{N} integrators:
The easiest solution is to use the regular aws-sdk along with nativescript-nodeify. Instructions for aws and cognito are at the bottom of this page. It takes care of making a bunch of dependencies (i.e crypto, fs) NativeScript-compatible
Related
I'm using NPM module ip (https://www.npmjs.com/package/ip) in an Angular app to do some parsing/comparation of IP addresses. Everything was working fine, but when I try to build the application for production using ng build --prod --aot, the compiler complains with the following error:
ERROR in ./node_modules/ip/lib/ip.js Module not found:
Error: Can't resolve 'os' in '/home/fel/Documentos/proyectos/IPGes/node_modules/ip/lib
It seems that the error comes because it tries to use the module os, which is only available in a node.js environment, not in the browser.
Does anybody know if there's a workaround that enables to use the ip npm module in an Angular compiled app?
Thanks in advance,
The ip library is a NodeJs specific library since it has a dependency on os. In some cases, you can have some luck using browserfy to make your node packages work in the browser. However, I don't think it'll work with this one.
I would suggest moving this logic to your server. If you're using node, just add the package there and surfaced an API endpoint to post an IP Address. Thay way, you can use the library as you wish.
The only reason why this works locally while running in Dev is that Angular is running a node server at that point. Once you bundle everything up, it's just a bunch of bundled HTML and JS.
Just in case anyone has the same trouble, I dropped the ip library (which is a great tool, but for Node projects) and I used ipaddr.js (https://www.npmjs.com/package/ipaddr.js), which has all the methods I've needed in the application.
Cheers,
I'm new to Reactjs, Nodejs and MongoDB. I'm currently trying to change Mediums snowflake tool to store users scores in a database. I have installed yarn, mongodb and mongodb-core through npm. It is a single page web application which is what I think is causing me trouble. I add
var MongoClient = require('mongodb');
To SnowflakeApp.js and encounter the following error:
Module not found: Error: Can't resolve 'dns' in
'/home/mlAHO174/snowflake/node_modules/mongodb-core/lib'
I've tried googling this error and have discovered it could be a range of things. I'm not sure if it is because React is front end and I'm trying to alter back end or because mongoDB is installed incorrectly. I'm new to this so would be grateful for help!
DNS is a core module of Node.JS. Telling people they need to install DNS via NPM will end up with them having a completely different module that does something else.
https://nodejs.org/api/dns.html vs https://www.npmjs.com/package/dns
This error most likely means you are trying to do something from the client-side that needs to be done on the server-side. If MongoDB module can't find the DNS component, it's running on the client-side.
MongoDB has to run on the server. In order to access data from React dynamically you'll need to set up an API using something like Express or Apollo.
Update:
A great way to do this is with Azure Functions (TypeScript) or AWS (Lambda) functions
For anyone who encounters this Error while importing the clientPromise (like in the with-mongodb template):
Make sure you're in the /pages/ directory!
It won't work in other directories like /components.
(and you should take a break or get some coffee...)
The problem is that you are trying to connect to the database from the front end. If this were possible that would open up a whole world of security issues. You need to set up your database connections on the backend and then have the front end make requests to the backend to handle the database.
I solved this by installing and using 'bson' instead of 'mongodb' for the client part of the code. 'bson' has a tiny bit of what 'mongodb' has and it might have what you are looking for. 'bson' is built for the browser.
In my case I needed the "ObjectId" in the browser and pulling it in from 'bson' did the trick as I didn't want to reference 'mongodb' because of the error described in the OP.
The other answers are also correct depending on why you're getting this error.
I think - mongo package is meant to be run on servers only, not in the browser.
It does not work in Next.js pages file components too, but does work in getStaticProps, getServerSideProps, getStaticPaths etc - because they run on the server, not the client.
Alternative - use Firebase Realtime database, you can access it in client-side code too. Example - a website (say a React app) that is hosted on GitHub pages or some other static server, but doesn't have a web app server (aka backend).
welcome to stack overflow.
You need to understand and learn few basics of web-applications. There's frontend, backend and a layer between them and a layer between backend and database. Frontend includes react.js, angular.js or anything else that is on browser. Backend is used to take request from frontend, providing API's to frontend and ask for data from other API's or database. Database includes sql, no-sql.
The error you are facing if of a NPM module mongodb-core.js. Either it's not installed properly, or installed using wrong version of module which is not comparable with your node version, or wrong version of NPM, or module using another NPM module which is not installed.
The issue in your case is mongodb-core uses a module dns which is not been installed. Try to install dns with npm i dns. or remove and install mongodb-core again.
I'd like to know why there isn't a npm / yarn package to Twilio Client Javascript SDK 1.4.
I'm trying to use their voice service, following this tutorial, but in React Native.
Is this package for browser usage only? How could I have access to Twilio.Client on react-native?
I already implemented a programmable-chat with success, using the provided packages twilio-chat and twilio-common.
Meanwhile, is there any way of importing a remote file or using a local javascript file (twilio.min.js) to a react-native app?
Thanks in advance.
EDIT:
Further research lead me to believe that this SDK only work for browsers since it has to deal with audio events, connection status etc.
Correct me if I'm wrong.
I'm now trying to implement react-native-twilio-programmable-voice
.
I'm trying to use a Node.js based component (https://github.com/leandrowd/react-responsive-carousel) in my Figwheel-based ClojureScript app.
Unfortunately I cannot find a "standalone", packaged Javascript file with react-responsive-carousel. Since my app is not run by Node.js, it cannot require etc.
Is there either an elegant way to reuse Node.js libraries from ClojureScript, or a solution to package any Node.js library into a standalone file?
You can use Webpack to turn the library and all its dependencies into a single JavaScript file which exports a reference for the library.
In carousel-module.js
global.Carousel = require('react-responsive-carousel').Carousel;
Check out the Webpack page for how to set up Webpack.
It's unfortunate that we still have to go through this convoluted method to use CommonJS libraries. I hope native support is coming soon.
So I have been fiddling around with Netsuite and I want to know if it is possible to use Node.js or npm modules within a SuiteScript or Suitelet?
My goal is to use a few npm modules within Netsuite to interact with Amazon's MWS API.
No, it's a different Javascript engine. Rhino I believe.
You can use various JS libraries but Node modules are usually written with that engine in mind.