0

I am new to programming and started with tabris-js mobile app development framework for pure javascript. Tabris-js supports using npm modules an cordova plugins to extend.

I tried to import mqtt-js npm library into tabris-js app. Locally installed the library to path; project_folder/node_modules/mqtt/mqtt.js and added dependency in package.json.

When importing the module:

const mqtt = require('mqtt'); 

The error is: could not parse the module .../mqtt.js

Isn't mqtt-js compatible with tabris-js or is this a global issue?

Anthony Kong
  • 37,791
  • 46
  • 172
  • 304
Tragedart
  • 1
  • 1
  • Have you installed like - npm install mqtt – PRADEEP Kumar Nov 14 '17 at 08:58
  • Yes I did - npm install mqtt - in project_folder. And I see the module - project_folder/node_modules/mqtt/mqtt.js - and also dependency added in package.json itself. I tried to run my app both in Tabris.js 2 developer app and build app. This is a module parse error not module find error really i don't know the difference so. – Tragedart Nov 14 '17 at 10:28
  • Try running your script through Node to see if you have the same problem. For example, if the `main` entry in `package.json` is `app.js` then run `node app.js` from the command line. If it's the same issue, then it's a problem with mqtt. – Cookie Guru Nov 14 '17 at 17:03
  • Cookie Guru I am trying right now and yes it is working ! - node app.js - is working. I got my message echoed from online public broker. So what am I doing wrong in my tabris app? – Tragedart Nov 14 '17 at 17:13
  • @Tragedart probably as Tim Buschtöns [suggested on Slack](https://tabrisjs.slack.com/archives/C0AQ5BK36/p1510662128000219) – Cookie Guru Nov 14 '17 at 21:21

1 Answers1

0

From the document; MQTT.js is a client library for the MQTT protocol, written in JavaScript for node.js and the browser. To use MQTT.js in the browser see the browserify section.

I tested in the same way and this worked well. Browserified node_modules/mqtt/mqtt.js module to a browsermqtt.js and required this bundle into my tabris-js app. And use MQTT over Websockets port to the broker.

Tragedart
  • 1
  • 1