node-mysql2
node-mysql2 copied to clipboard
require('mysql2') breaks "npm start"
If i add to my project
const mysql = require('mysql2');
and launch my nodejs project with npm start
i get error
/nodejs_project/node_modules/lru-cache/dist/cjs/index.js:359
#initializeTTLTracking() {
^
SyntaxError: Unexpected token '('
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/home/helar/projects/nodejs/nodejs_udemy/10_sql_intro/node_modules/lru-cache/dist/cjs/index-cjs.js:5:36)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
Setup: OS: Ubuntu 22.04.1 LTS Nodejs: v12.22.9 mysql2: [email protected]
This problem seems to start from verstion [email protected]. [email protected] is ok.
Are you able to upgrade node version? node v12 is currently one year past its end of life.
@sidorares you might want to update https://github.com/sidorares/node-mysql2/blob/master/package.json#L54 to say >= 14 just for consistency.
In the future, it might also be nice to point out dropping support for Node.js versions as a breaking change in the changelog. Of course, one might find it debatable whether such a warning is necessary for EOL versions of Node.js.
Faced similar error on my end.
In the end, I've upgraded my node version and it works.
this work fine on the backend , but at cpanel where i have following node version
- 10.24.1
- 11.15.0
- 12.22.9
- 14.18.3
- 16.17.0
and i ahve tried mysql2 veriosn 3.2.0, 3.2.1 3.3.0, 3.4.0 , but non of the above is working .
Use terminal:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
source ~/.bashrc
node -v
nvm install v20.11.0
node -v