0

我正在尝试在 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不同的方式设置文件的权限,chmod777到目前为止没有任何效果。我有点绝望,因为我很长一段时间都没有改变这部分的任何东西,它突然停止工作。

我使用的命令:

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');
         });
4

2 回答 2

1

问题是最新的 sqlite3 4.0.8 版本在这个 ARM 处理器上不能正常工作。我将它降级到 4.0.6,现在它可以完美运行。

于 2019-05-24T05:49:58.107 回答
0

sqlite3从version升级到4.0.4version时,我也遇到了这个问题4.1.0。固定我的依赖以4.0.4使其再次工作。您还可以在此处此处查看其他一些解决方法,并在此处讨论浏览器环境中的用法。

于 2020-01-24T00:24:16.077 回答