SyntaxError: Invalid or unexpected token: error parameterizing the node node-red-contrib-stackhero-mysql

Hello. I am new using node-red. I've only been working with this system for a couple of months. So far I'm doing fine, but my first problem that I can't solve happened when I tried to compile the nodes node-red-node-mysql and node-red-contrib-stackhero-mysql to connect to a mysql database that I have installed on the local server where node-red is installed. A PC with w10 64bit. With any of these two nodes, just at the moment that I finish parameterizing with the data of my database and execute a deploy, the node-red collapses, stops and shows the error that I share below. I cannot parameterize any node to connect to my database that does not stop the node-red abruptly. I use a database server running on wampserver 3.2.6. The wampserver has mysql version 5.7.36 and mariaDB version 10.6.5.
Below I share the error code. I would greatly appreciate your help:

node-red-contrib-stackhero-mysql
node-red-node-mysql

Welcome to Node-RED

9 Apr 13:11:11 - [info] Node-RED version: v2.2.2
9 Apr 13:11:11 - [info] Node.js version: v16.13.2
9 Apr 13:11:11 - [info] Windows_NT 10.0.10240 x64 LE
9 Apr 13:11:12 - [info] Loading palette nodes
9 Apr 13:11:15 - [info] Dashboard version 3.1.6 started at /ui
9 Apr 13:11:15 - [info] Settings file : C:\Users\home.node-red\settings.js
9 Apr 13:11:15 - [info] Context store : 'default' [module=memory]
9 Apr 13:11:15 - [info] User directory : \Users\home.node-red
9 Apr 13:11:15 - [warn] Projects disabled : editorTheme.projects.enabled=false
9 Apr 13:11:15 - [info] Flows file : \Users\home.node-red\reload
9 Apr 13:11:15 - [info] Server now running at http://127.0.0.1:1880/
...
9 Apr 14:39:12 - [info] Installing module: node-red-contrib-stackhero-mysql, version: 1.0.5
9 Apr 14:39:58 - [info] Installed module: node-red-contrib-stackhero-mysql
9 Apr 14:39:59 - [info] Added node types:
9 Apr 14:39:59 - [info] - node-red-contrib-stackhero-mysql:Stackhero-MySQL-Server
9 Apr 14:39:59 - [info] - node-red-contrib-stackhero-mysql:Stackhero-MySQL
9 Apr 14:40:19 - [info] Stopping flows
9 Apr 14:40:19 - [info] Stopped flows
9 Apr 14:40:19 - [info] Starting flows
9 Apr 14:40:20 - [error] [Stackhero-MySQL:6a26e292eb5c6fc1] MySQL database not configured
9 Apr 14:40:20 - [info] Started flows
9 Apr 14:44:07 - [info] Stopping flows
9 Apr 14:44:07 - [info] Stopped flows
9 Apr 14:44:07 - [info] Starting flows
9 Apr 14:44:07 - [info] Started flows
9 Apr 14:44:07 - [red] Uncaught Exception:
9 Apr 14:44:07 - [error] C:\Users\home.node-red\node_modules\iconv-lite\encodings\internal.js:1
$�)

SyntaxError: Invalid or unexpected token
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1031:15)
at Module._compile (node:internal/modules/cjs/loader:1065:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object. (C:\Users\home.node-red\node_modules\iconv-lite\encodings\index.js:6:5)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.getCodec (C:\Users\home.node-red\node_modules\iconv-lite\lib\index.js:63:27)
at Object.getDecoder (C:\Users\home.node-red\node_modules\iconv-lite\lib\index.js:125:23)
at Object.exports.decode (C:\Users\home.node-red\node_modules\mysql2\lib\parsers\string.js:10:25)
at Packet.readNullTerminatedString (C:\Users\home.node-red\node_modules\mysql2\lib\packets\packet.js:398:25)
at Function.fromPacket (C:\Users\home.node-red\node_modules\mysql2\lib\packets\handshake.js:62:33)
at ClientHandshake.handshakeInit (C:\Users\home.node-red\node_modules\mysql2\lib\commands\client_handshake.js:93:40)
at ClientHandshake.execute (C:\Users\home.node-red\node_modules\mysql2\lib\commands\command.js:39:22)

You should fix that error! You need to open the MySQL node and enter the configuration information.

If NR crashes at startup, run it in safe mode. Add --safe (two dashes) to the end of the startup command. So if your flow is ‘my.flow’ you would use node-red my.flow --safe This will allow you to use the editor and configure the MySQL node and deploy.

A side question: why are you using two different MySQL nodes?

Hello. thank you very much for your help. I am not using two mysql node, initially I tried node-red-node-mysql and it installed correctly but when configuring it and executing deploy node-red crashed. then I thought it was a problem with node-red-node-mysql, I uninstalled it and installed node-red-contrib-stackhero-mysql to test, it was also installed correctly and when I configured the data of my database server and executed deploy
the same error occurred, the node-red crashed too, and it was the log I shared above.

What happens if you remove both nodes and remove their configuration nodes?

If I remove both nodes, the node-red works perfectly, that is, all the other flows work fine. I have nodes that read through modbus from a PLC, I have nodes that send data by telegram and by whatsapp and everything works, except when I configure any of these two mysql nodes, which from the moment I configure the database server and I hit deploys, everything stops. To load NR again I have solved by executing NODE-RED CLEAR on some occasions and on others I have had to delete the mysql node folder in the path ....node-red\node_modules .
I have already executed the node-red myflow --safe command and I get the same problem.
Thank you very much for continuing to support me. I remind you I don't have much experience in using node-red. I also apologize for my English, which is not very good, because my main language is Spanish.

Please try this.
1 - stop node-red
2 - start node-red with a new flow `node-red testmysql.flows
3 - add in the one of the MySQL nodes, configure it and deploy

Does it cause an error?
If it doesn’t try adding enough nodes to actually query the DB and see what happens.

Same thing. Same problem :frowning:
just before de fallowing line i press "Deploy" after configured de DB parmeters, them crash:--- 10 Apr 16:16:38 - [red] Uncaught Exception:

Here the full log:

Your environment has been set up for using Node.js 16.13.2 (x64) and npm.

C:\Windows\System32>node-red testmysql.flows
10 Apr 16:14:51 - [info]

Welcome to Node-RED
===================

10 Apr 16:14:51 - [info] Node-RED version: v2.2.2
10 Apr 16:14:51 - [info] Node.js  version: v16.13.2
10 Apr 16:14:51 - [info] Windows_NT 10.0.10240 x64 LE
10 Apr 16:14:53 - [info] Loading palette nodes
10 Apr 16:14:56 - [info] Dashboard version 3.1.6 started at /ui
10 Apr 16:14:56 - [info] Settings file  : C:\Users\home\.node-red\settings.js
10 Apr 16:14:56 - [info] Context store  : 'default' [module=memory]
10 Apr 16:14:56 - [info] User directory : \Users\home\.node-red
10 Apr 16:14:56 - [warn] Projects disabled : editorTheme.projects.enabled=false
10 Apr 16:14:56 - [info] Flows file     : \Users\home\.node-red\testmysql.flows
10 Apr 16:14:56 - [info] Creating new flow file
10 Apr 16:14:56 - [info] Server now running at http://127.0.0.1:1880/
10 Apr 16:14:56 - [info] Starting flows
10 Apr 16:14:56 - [info] Started flows
10 Apr 16:16:38 - [info] Stopping flows
10 Apr 16:16:38 - [info] Stopped flows
10 Apr 16:16:38 - [info] Starting flows
10 Apr 16:16:38 - [info] Started flows 
10 Apr 16:16:38 - [red] Uncaught Exception:
10 Apr 16:16:38 - [error] C:\Users\home\.node-red\node_modules\iconv-lite\encodings\internal.js:1
$�)


SyntaxError: Invalid or unexpected token
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\home\.node-red\node_modules\iconv-lite\encodings\index.js:6:5)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.getCodec (C:\Users\home\.node-red\node_modules\iconv-lite\lib\index.js:63:27)
    at Object.getDecoder (C:\Users\home\.node-red\node_modules\iconv-lite\lib\index.js:125:23)
    at Object.exports.decode (C:\Users\home\.node-red\node_modules\mysql2\lib\parsers\string.js:10:25)
    at Packet.readNullTerminatedString (C:\Users\home\.node-red\node_modules\mysql2\lib\packets\packet.js:412:25)
    at Function.fromPacket (C:\Users\home\.node-red\node_modules\mysql2\lib\packets\handshake.js:62:33)
    at ClientHandshake.handshakeInit (C:\Users\home\.node-red\node_modules\mysql2\lib\commands\client_handshake.js:98:40)
    at ClientHandshake.execute (C:\Users\home\.node-red\node_modules\mysql2\lib\commands\command.js:45:22)

C:\Windows\System32>

What did you put in the settings and which MySQL node did you use?

I am using the following mysql node:
node-red-node-mysql (node) - Node-RED.
The configuration is attached in an image.


Using the same configuration taked from the mysql client (Heidisql)


Using an SQL node I connect perfectly to a database in SQL. Using the following node:

I would like to try to solve the problem I have with the mysql node, otherwise I will have to migrate to SQL and I don't want to.

Hi,

Lets start from the beginning to see if we can resolve this.

Please try to answer each question...

  1. Where are things installed?

    • Are node-red and mysql running on the SAME computer?
  2. How many sql type nodes do you have installed? (enter sql in the search box on the help sidebar) image

  3. what does npm list mysql2 show?

  cd C:\Users\home\.node-red
  npm list mysql2

On my PI it looks like this...
image

Hello. thank you very much for your help. I will answer your questions below:

  1. Yes. node-red and mysql are installed on the same PC

mysql1
3.
mysql2

Have you recently upgraded node-red and/or nodejs?
e.g. was node-red and node-js previously installed and updated to newer versions?

This :point_up_2: is most odd. Almost like there is corruption - possibly in your .node-red\node_modules, possibly in your global nodejs installation.

Could you setup a mysql node and its config so that this happens again & export it (select the mysql node, press CTRL-E to export, paste into a reply) - NOTE - password and user name will not be exposed (credentials are not exported).
I will look see if there are any odd characters in the export.

In the mean time, if you want to proceed, the next step I suggest is to assume there is a problem with the .node-red\node_modules part (after that would be to remove and re-install nodejs)

  • shut down node-red
  • open c:\users\home in your file explorer
  • locate the folder .node-red
    • you might need to switch on show hidden files and folders in explorer options
  • rename .node-red to .node-red-old
  • start node-red
    • this will re-create the folder c:\users\home\.node-red
  • install (from the palette manager) node-red-node-mysql
  • try a simple demo (inject topic=select * from datos --> mysql --> debug)

You can always switch back to (or simply import your old flows into the fresh node-red) from the back-ed up folder C:\Users\home\.node-red-old (i.e. you wont lose anything trying this)

Hello.
Below I share the result of executing CTRL-E in the configured mysql node and just before executing a DEPLOY. Remember that if I press DEPLOY after configuring node mysql node-red crashes.

[
    {
        "id": "30c5315b6e8cd583",
        "type": "mysql",
        "z": "09ca3869f8ec24df",
        "mydb": "835fdbf2b7c14e88",
        "name": "",
        "x": 270,
        "y": 60,
        "wires": [
            [ ]
        ]
    },
    {
        "id": "835fdbf2b7c14e88",
        "type": "MySQLdatabase",
        "name": "",
        "host": "127.0.0.1",
        "port": "3306",
        "db": "nodereddb",
        "tz": "",
        "charset": "UTF8",
        "credentials": {
            "user": "root",
            "password": ""
        }
    }
]

I will also try the second thing you propose. I'll keep you up to date.
Greetings and thank you very much for your time.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.