MQTT nodes fail to run in NodeJS version < 8.10.x
See original GitHub issueWhat 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]))/
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:
- Created 3 years ago
- Comments:5 (5 by maintainers)
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
Sounds good. We can give that a shot for now. Feel free to close the issue. 👍