Import MQTT NPM module into NativeScript - javascript

I'm trying to use MQTT npm package as part of a NativeScript application I'm building.
I'm running into a problem when I try to require it.
My code uses the var mqtt = require('mqtt'); as the example indicates, but when trying to compile the NativeScript application, I get the following error :
com.tns.NativeScriptException: Failed to find module: "mqtt", relative
to :/app/tns_modules.
I've verified that the mqtt folder is in my node_modules folder, and I tried creating a tns_modules folder and copying the mqtt folder there as well.
However I'm still getting the error. I tried loading the knock-knock-jokes package and that loads perfectly.
I'm using the latest versions of Node and NativeScript as 13 April 2016 (4.4.0 for Node and 1.7.1 for NativeScript).

Ok, I tried this out to see why this is happening.
The very first line of mqtt.js is
#!/bin/node...
Which is invalid JavaScript code. Node has been programmed to ignore it; but NativeScript does not. (Might be worth a enhancement request..)
So when it loads this file to parse it, it fails to parse and returns that it isn't available. (Not always the best error on parse issues)
HOWEVER, if you fix that error you will run into MORE issues. It will then complain about not finding the "net" library. NativeScript does not have a net library built in. To my knowledge no one has yet created a net replacement for NativeScript. So, in a lot of cases you can use node modules as is; but if they call anything that depends on a built in node library; they unfortunately will not currently work in NativeScript as their is no equivalent library existing.
Just looking at the dependencies of the mqtt library; your odds of getting this working on NativeScript looks at a glance pretty slim.

Related

Not able to fork external JavaScript server file in Electron

so I am making an application that requires a backend API, and it uses certain node_modules which don't work when compiling with Electron. To fix this, I put the API code into a separate JavaScript file, which I am attempting to fork using child_process.
I have gotten this to work when compiling, but it immediately stops working after I move the "win-unpacked" folder or try to install the app using the compiled installer.
I have checked, and it is not the path that is wrong, it is correctly pointing to the file. From testing, it appears that the file actually does get forked, but immediately exits with the status code 1.
I can't use require(./filepath.js) because that will just include the code in the compiler, which doesn't work with the modules I am using.
I am hoping someone knows what is wrong and what I should do to fix it, or have any ideas for other ways to run the server code without including it in the compiler.
I am using Vue.js 3 and vue-cli-electron-builder version 2.1.1
The server I am attempting to run is a express server.

How to build a "pure" web browser application client for Aws Chime?

I'm creating a meeting web application and at server side I'm using php sdk, everything is ok and I'm able to create meeting and attendees and get the returned data with ids, join tokens etc. Now I'm stucked on aws demo application client because it seems to work only with React. I've tried to embed amazon-chime-sdk-js via cdn(https://cdn.jsdelivr.net/npm/amazon-chime-sdk-js#2.10.0/build/index.min.js) but without success, console shows 2 errors:
Uncaught ReferenceError: exports is not defined at index.js:2
aws_meet.php:20 Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules
I guess this is due to the absence of modules support on browsers, right? Is there any sample with no React needing or is it mandatory to use that?
As the Chime SDK is in typescript you can use the typescript compiler to compile it to Javascript and then bundle it using a module bundler such as Webpack.
You can find more about it here: Web application component architecture section
Example:
git clone https://github.com/aws/amazon-chime-sdk-js.git
cd amazon-chime-sdk-js/demos/singlejs
npm run bundle
It will generate an amazon-chime-sdk.min.js and amazon-chime-sdk.min.js.map in the build folder. Include both files in your project and embed amazon-chime-sdk.min.js
<script src="path/to/amazon-chime-sdk.min.js"></script>
You can find the complete example here: Chime SDK Single JS
Thank you #tahiaji for highlighting about the broken link.

I get "ReferenceError: Can't find variable: require" running a Cordova app on osx

I am trying to develop a Cordova based app that uses the ytdl-core node module. From my understanding, Cordova uses node-js for running the app on osx (or other non-browser platforms). The app builds successfully and it opens on my Mac, but the javascript won't work since it throws this error on open and/or refresh:
"modify in config.xml.
2020-05-23 20:11:32.639 Weather[11707:374910] JavaScript error: index.js:11: ReferenceError: Can't find variable: require"
index.js:11 is this line: const ytdl = require('ytdl-core');
Most people with this error are getting it because browsers do not support "require", but as I said, I'm running on osx platform. I already checked that node.js is installed and the ytdl-core is in the node_modules folder of my project.
Here is my git repository: https://github.com/FCjosh/JRMusicapp.git
I installed cordova exactly as it says on their website with xcode. One more thing worth mentioning is that I am using Jquery although I don't think that is problematic with node.js.
UPDATE
After tons of research, I have reason to believe that the reason the Javascript file cannot use the require function is because Cordova is treating it like a browser would. I have three ideas for solutions that may or may not work:
Cordova Plugins - A plugin runs natively and perhaps some sort of nodeJS plugin specific to the ytdl dependencies could be made.
Browserify, Webpack, or the like. From my understanding, these let you run serverside code on a browser. This seems pretty straightforward and a likely to work solution.
Create a native app and embed cordova. I don't know how to make a native app and if I did, I wouldn't be using Cordova. So I will not pursue this option, but I could understand situations where embedding Cordova in a native app is very useful.
I began making a plugin, but I got stuck when I got to the Objective C part and I have no idea how to implement nodeJS into the plugin. I am changing routes to the Browserify/Webpack solution because the plugin is over my head and making a native app is also over my head.
I will update again soon if the Browserify/Webpack solution works.

Error while attempting to add packages in Meteor

So I am very new to Meteor, and I was sifting through some example apps and open source projects when I came across this simple chat application:
(https://github.com/BenderV/simplechat)
I wanted to download the project, run it on my local server, and mess around with the code to learn more about what does what, and how to use the Meteor framework. I simply downloaded the .zip file from github and tried to run it (using the meteor in my terminal. However I got the following error when I ran the application locally in my browser:
Your app is crashing. Here's the latest log.
=> Errors prevented startup:
While building the application:
error: no such package: 'accounts-guest'
error: no such package: 'user-status'
error: no such package: 'accounts-testing'
error: no such package: 'fontawesome4'
error: no such package: 'iron-router'
error: no such package: 'bootstrap-3'
error: no such package: 'fast-render'
error: no such package: 'jquery-titlealert'
error: no such package: 'related'
=> Your application has errors. Waiting for file change.
I can (obviously) infer from the nature of the log that the error that I am experiencing is because I don't have the correct packages installed (the one that are listed, obviously).
So keeping this in mind, I researched how to add packages to meteor (using instructions I found on Atmosphere JS pages of the respective packages). However, when I entered the command that was provided by Atmosphere into my terminal (for example for, 'accounts-guest' package I entered: meteor add artwells:accounts-guest). Unfortunately doing this did not work, and I was given something like the following error in the terminal: artwells:accounts-guest: no such package
I have no idea what to do, the packages will not install so I can not try this code. I come from experience with Rails, and in Rails if you needed to install "gems" (pretty much the same thing as packages in Meteor) you could just enter bundle install into the terminal to download and install undefined packages. Is there something like this in Meteor? I have heard of something called Meteorite, but am unsure what it is and how to use it.
Anyways I really would appreciate any help in getting me past this minor roadblock on my way to learning Meteor!
Thank you
That's an older project which use the old packaging system 'meteorite' = 'mrt' on the command line.
I suggest you try a newer example, Meteor ships with a few. Once you have Meteor installed you can create an example app by typing one of the following commands :
meteor create --example leaderboard
meteor create --example todos
meteor create --example localmarket
And yes, there is a very similar mechanism to the gems commands you are accustomed to. Simply running a project 'meteor' should download its dependencies. Also you can run 'meteor update' if you want to update to the latest versions for your project.
Last August there was a major update to the meteor package management system, you can read more about it here : https://www.meteor.com/blog/2014/08/26/meteor-090-new-packaging-system
So, for any examples you'd like to check out, try and get a recent one, from meteor 1.0. In newer versions of meteor those instructions on Atmosphere should work out fine for you.
You can see what version of meteor a project is running by looking at this file ".meteor/release" inside a meteor project :
https://github.com/BenderV/simplechat/blob/master/.meteor/release
so you can see that one is old.
good luck!

Failing to build a node.js plugin that references the libjpeg library

I have copied the libjpeg library into the 'c' directory where I am keeping the C and C++ source code for my node.js application.
I have used the binding.gyp file to point to the C++ file, and it has built successfully. However, when I add the line
#include "libjpeg-master/jpeglib.h"
I get the error message
fatal error C1083: Cannot open include file: 'jconfig.h': No such file or directory [...]
I am attempting to build the libjpeg library alongside the node.js code, rather than first building libjpeg using the build configuration there.
How should I go about solving this. If the answer is to use the build configuration from libjpeg, how can I get that to work when building a node.js plugin?
I am currently developing this on Windows but I want to get this working properly for all platforms.

Categories