Mysql2 require breaks with Node 12 (#5579)

This commit is contained in:
Olivier Cavadenti 2023-06-20 11:34:42 +02:00 committed by GitHub
parent 5ffe289c33
commit 0f8bbe92b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -37,6 +37,10 @@ jobs:
- name: Run npm install
run: npm install
- name: Run npm install mysql2@3.2.0 if Node 12.x
run: npm install mysql2@3.2.0
if: matrix.node-version == '12.x'
- run: npm run build
- name: Run Tests

View File

@ -14,6 +14,26 @@ class Client_MySQL2 extends Client_MySQL {
_driver() {
return require('mysql2');
}
initializeDriver() {
try {
this.driver = this._driver();
} catch (e) {
let message = `Knex: run\n$ npm install ${this.driverName}`;
const nodeMajorVersion = process.version.replace(/^v/, '').split('.')[0];
if (nodeMajorVersion <= 12) {
message += `@3.2.0`;
this.logger.error(
'Mysql2 version 3.2.0 is the latest version to support Node.js 12 or lower.'
);
}
message += ` --save`;
this.logger.error(`${message}\n${e.message}\n${e.stack}`);
throw new Error(`${message}\n${e.message}`);
}
}
validateConnection(connection) {
return (
connection &&