我在尝试执行作业时遇到错误。
import * as loopback from 'loopback';
import * as boot from 'loopback-boot';
import {JobEntrypoint} from '../utils/jobs/JobEntrypoint';
import {WinstonLoggerFactory} from '../utils/logging/WinstonLoggerFactory';
import {LoggingCategoryType} from '../../shared/all/types/LoggingCategoryType';
import {IConfig} from './IConfig';
import * as config from './config';
import {HashLinkedLogFactory} from '../../shared/all-servers/logging/HashLinkedLogFactory';
import {debug} from "util";
HashLinkedLogFactory.initializeInstance((config as IConfig).signedInitialisationVector.initialisationVector);
const app: any = module.exports = loopback();
const logger = new WinstonLoggerFactory().getBootLogger();
console.log('--> server');
// Bootstrap the application, configure models, datasources and middleware.
// Sub-apps like REST API are mounted via boot scripts.
boot(app, __dirname, async (bootError) => {
console.log('--> server 1');
if (bootError) {
logger.error('Error during boot', {
bootError: bootError,
category: LoggingCategoryType.Server
});
console.log('--> server 2');
process.exit(1);
}
const jobEntrypoint = new JobEntrypoint(app, logger);
if (jobEntrypoint.hasJobToExecute()) {
console.log('--> server 3');
try {
await jobEntrypoint.executeJob();
logger.info('done!', {category: LoggingCategoryType.Jobs});
process.exit(0);
} catch (error) {
logger.error('failed!', {error: error, category: LoggingCategoryType.Jobs});
process.exit(1);
}
} else {
throw new Error('No job to execute (at least one is expected)');
}
});
当我调试时,我了解到引导脚本正在加载,并且引发了一个错误,即它无法“创建数据源并且无法连接剩余初始化程序,然后无法读取未定义的属性'root'。”
TypeError: Cannot create data source "bank-server": Cannot initialize connector "rest": Cannot read property 'root' of undefined
。
有人遇到此错误吗?
答案 0 :(得分:0)
感谢您的评论。解决了datasources.local.js中的变量名称不匹配。变量名称更正后,它已得到修复。