Knex:如何在 ARM 上修复 "Cannot read property 'prototype' of undefined" 以进行初始设置

Knex: How to fix "Cannot read property 'prototype' of undefined" on ARM for initial-setup

我试图在 ARM 设备上使用 knex 初始化 sqlite3 数据库,但出现错误:

内克斯:运行

$ npm install sqlite3 --save
TypeError: Cannot read property 'prototype' of undefined
    at inherits (/home/user/node_modules/sqlite3/lib/sqlite3.js:27:16)
    at Object.<anonymous> (/home/user/node_modules/sqlite3/lib/sqlite3.js:66:1)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Client_SQLite3._driver (/home/user/sWave-Gateway/node_modules/knex/lib/dialects/sqlite3/index.js:79:12)
    at Client_SQLite3.initializeDriver (/home/user/sWave-Gateway/node_modules/knex/lib/client.js:254:26)
    at Client_SQLite3.Client (/home/user/sWave-Gateway/node_modules/knex/lib/client.js:115:10)
    at new Client_SQLite3 (/home/user/sWave-Gateway/node_modules/knex/lib/dialects/sqlite3/index.js:62:20)
    at Knex (/home/user/node_modules/knex/lib/index.js:60:34)
    at Object.<anonymous> (/home/user/dist/db/knex-data-access-layer/index.js:28:28)
    at Module._compile (module.js:653:30)

我已经尝试过以不同的方式设置 NODE_ENV 将带有 chmod 的文件的权限设置为 777 但到目前为止没有任何效果。我有点绝望,因为我很长时间没有对这部分进行任何更改,它突然停止工作了。

我使用的命令:

NODE_ENV=production node dist/initial-setup.js

它执行以下代码:

import * as config from 'config';
import * as crypto from 'crypto';
import * as fs from 'fs';
import * as mkdirp from 'mkdirp';
import * as path from 'path';
import { boot } from './boot';
import * as constants from './constants';
import { dataAccessLayer } from './db';
import * as shell from 'shelljs';
// tslint:disable:no-console

boot();

let logPath: string = config.get(constants.CONFIG_LOG_DIR);
if (!fs.existsSync(logPath)) {
  console.log(`Creating logs directory at ${logPath} ...`);
  mkdirp.sync(logPath);
}

let secretDirPath: string = config.get(constants.CONFIG_SECRET_DIR);
if (!fs.existsSync(secretDirPath)) {
  console.log(`Creating secret directory at ${secretDirPath} ...`);
  mkdirp.sync(secretDirPath);
}

let jwtSecret: string = crypto.randomBytes(config.get(constants.CONFIG_JWT_RANDOM_BYTES)).toString('hex');
let jwtSecretPath: string = path.join(secretDirPath, config.get(constants.CONFIG_JWT_SECRET_FILE));
fs.writeFileSync(jwtSecretPath, jwtSecret, 'utf8');

async function setupDb(): Promise<void> {
  await dataAccessLayer.migrate();

  try {
    await dataAccessLayer.seed();
  } catch (e) {
    // ignore missing production seeds, rethrow otherwise
    if (e.toString().indexOf('volatile-seeds/production') === -1) {
      throw e;
    }
  }
}

setupDb().catch(e => console.log(e))
         .then(()=> {
           shell.exec('tskill node');
         });

问题是最新的 sqlite3 4.0.8 版本无法在此 ARM-processor 上正常运行。我将它降级到 4.0.6,现在它可以正常工作了。

我从sqlite3版本4.0.4升级到4.1.0版本时也遇到了这个问题。将我的依赖固定到 4.0.4 让它再次工作。您还可以查看其他一些解决方法 here and here, and discussion of usage in browser environments here.