question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MQTT nodes fail to run in NodeJS version < 8.10.x

See original GitHub issue

What are the steps to reproduce?

Install and use NodeJS version <8.10.x. Reproduced on Node version 8.9.4 using Node-RED version 1.0.5. Can be reproduced by adding a single MQTT node configured to a dummy server and pressing deploy.

What happens?

Core MQTT nodes throw errors when the Node-RED instance is started or deployed. This leads to the MQTT node not working.

Stack trace:

10 Apr 18:08:06 - [error] [mqtt-broker:1c8e4249.e36a3e] SyntaxError: Invalid regular expression: /(?:^|(?<=\s))(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}
|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1
}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/: Invalid group                                                                                                                                                                        
10 Apr 18:08:06 - [error] [mqtt out:2fac9c43.c2f204] missing broker configuration 

The reason is because the the regex used to check for the IPv6 string inside /@node-red/nodes/core/network/10-mqtt.js +157 is using a fancy lookbehind regex that wasn’t supported until NodeJS 8.10.x.

I suggest switching over to using the regex below that doesn’t use any lookbehind clauses for the IPv6 string match instead and it has been tested to work with the older nodejs version.

/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/

Source

I haven’t tested this regx against #2462 (which I think is also the issue that caused the bug) so there might be some regression needed there.

What do you expect to happen?

No errors thrown and MQTT node working as intended when using the supported node version 8.x as listed in the Node-RED docs.

Please tell us about your environment:

  • Node-RED version: 1.0.5
  • Node.js version: 8.9.4
  • npm version: 5.6.0
  • Platform/OS: Ubuntu 18
  • Browser: Chrome

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dceejaycommented, Apr 11, 2020

Nodejs 8 has dropped support since Oct 2019. https://blog.risingstack.com/update-nodejs-8-end-of-life-no-support/ please consider upgrading to node 10 or 12 LTS

0reactions
tedhuangcommented, Apr 15, 2020

Sounds good. We can give that a shot for now. Feel free to close the issue. 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using the Node.js MQTT Client -Starting Guide
Tutorial showing how to use the Node.js MQTT Client. ... The node client provides the error event for a connection failure.
Read more >
The engine "node" is incompatible with this module
yes , you are getting this error because of incompatibility between the package version and node engine. – Shubham Sharma. Jun 16, 2019...
Read more >
How to use MQTT in Node.js | EMQ
This article introduces how to use MQTT in the Node.js project, and implement the connection, subscription and messaging, etc of MQTT.
Read more >
How to Easily Update Node.js to the Latest Version
There are several easy & quick ways of upgrading Node.js. Learn how to update ... You can also use it to update your...
Read more >
mqtt - npm
js is a client library for the MQTT protocol, written in JavaScript for node.js and the browser. MQTT.js vNext. Want to contribute to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found