突然搞一下2年前的node.js项目,环境搭好之后npm install安装完成,但是在npm run dev之后一直跑不起来,报语法错误。分别在node_modules\ali-rds\lib目录下operator.js和transaction.js文件,修改这2个文件里面的包含‘#’号的函数,可能是新库老版本的node.js不支持这种写法,全部替换成‘_’下划线,部分代码
operator.js
async lockOne(tableName, lockType, tableAlias) {
const sql = this._locks([{
tableName,
lockType,
tableAlias,
}]);
debug('lock one table \n=> %j', sql);
return await this.query(sql);
}
_locks(tableLocks) {
if (tableLocks.length === 0) {
throw new Error('Cannot lock empty tables.');
}
let sql = 'LOCK TABLES ';
for (let i = 0; i < tableLocks.length; i++) {
const table = tableLocks[i];
const { tableName, lockType, tableAlias } = table;
if (!tableName) {
throw new Error('No table_name provided while trying to lock table');
}
if (!lockType) {
throw new Error('No lock_type provided while trying to lock table `' + tableName + '`');
}
if ([ 'READ', 'WRITE', 'READ LOCAL', 'LOW_PRIORITY WRITE' ].indexOf(lockType.toUpperCase()) < 0) {
throw new Error('lock_type provided while trying to lock table `' + tableName +
'` must be one of the following(CASE INSENSITIVE):\n`READ` | `WRITE` | `READ LOCAL` | `LOW_PRIORITY WRITE`');
}
if (i > 0) {
sql += ', ';
}
sql += ' ' + this.escapeId(tableName) + ' ';
if (tableAlias) {
sql += ' AS ' + this.escapeId(tableAlias) + ' ';
}
sql += ' ' + lockType;
}
return sql + ';';
}transaction.js
async rollback() {
this._check();
try {
return await this.conn.rollback();
} finally {
this.isRollback = true;
this.conn.release();
this.conn = null;
}
}
async _query(sql) {
this._check();
return await this.conn._query(sql);
}
_check() {
if (!this.conn) {
throw new Error('transaction was commit or rollback');
}
}改完之后,再运行npm run dev就好了。
[egg-ts-helper] create typings\app\controller\index.d.ts (6ms)
[egg-ts-helper] create typings\app\middleware\index.d.ts (2ms)
[egg-ts-helper] create typings\app\model\index.d.ts (1ms)
[egg-ts-helper] create typings\config\index.d.ts (18ms)
[egg-ts-helper] create typings\config\plugin.d.ts (1ms)
[egg-ts-helper] create typings\app\service\index.d.ts (7ms)
[egg-ts-helper] create typings\app\index.d.ts (0ms)
2023-07-14 22:09:32,602 INFO 5688 [master] node version v12.18.2
2023-07-14 22:09:32,603 INFO 5688 [master] egg version 2.37.0
2023-07-14 22:09:33,789 INFO 12380 [egg-sequelize](1ms) Executed (default): SELECT 1+1 AS result
2023-07-14 22:09:33,783 INFO 5688 [master] agent_worker#1:12380 started (1177ms)
2023-07-14 22:09:35,449 INFO 7364 [egg-sequelize](1ms) Executed (default): SELECT 1+1 AS result
2023-07-14 22:09:35,455 INFO 5688 [master] egg started on http://0.0.0.0:7800 (2852ms)
本文链接:http://it72.com/12730.htm