Typescript knex:无法读取未定义的属性“客户端”

时间:2020-10-04 16:56:32

标签: typescript knex.js

我的knexfile:

import knex from 'knex';
import path from 'path';
const dotenv = require('dotenv').config();

interface KnexConfig {
  [key: string]: object;
}

const config: KnexConfig = {
  developement: {
    client: 'pg',
    connection: {
      host: process.env.DB_HOST,
      user: process.env.DB_USER,
      password: process.env.DB_PASS,
      database: process.env.DB_NAME,
    },
    pool: {
      min: 2,
      max: 10,
    },
    migrations: {
      directory: path.resolve(__dirname, 'src', 'infra', 'knex', 'migrations'),
    },
    timezone: 'UTC',
    useNullAsDefault: true,
  },
};
const KnexInstance = knex(config['development'] as knex.Config);
module.exports = KnexInstance;

我要迁移的目录是:src / infra / knex / migrations: 我的文件夹结构:

enter image description here

我的tsconfig:

{
  "compilerOptions": {
    "target": "es2020",
    "module": "CommonJS",
    "allowJs": true,
    "outDir": "./dist",
    "rootDir": "./src",
    "strict": true,
    "strictPropertyInitialization": false,
    "moduleResolution": "node",
    "baseUrl": "./src",
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "forceConsistentCasingInFileNames": true,
    "noImplicitAny": true,
    "typeRoots": ["node_modules/@types", "@types"],
    "paths": {
      "@modules/*": ["modules/*"],
      "@infra/*": ["infra/*"],
      "@config/*": ["config/*"]
    }
  },
  "include": ["src", "__tests__"],
  "exclude": ["node_modules"]
}

我在纱结上得到这个错误:

yarn knex migration:make add_custom_functions

错误:

需要外部模块ts-node / register(节点:10600) UnhandledPromiseRejectionWarning:TypeError:无法读取属性 未定义的“客户” 在Object.Knex [默认情况下](C:\ Users \ spiriT \ ms-emasa \ node_modules \ knex \ lib \ knex.js:22:42)

1 个答案:

答案 0 :(得分:1)

以下一行中出现拼写错误,结果config.development未定义。可能值得使用点访问器语法而不是方括号访问器,以使您的编辑器可以选择这种错字。

  developement: {