Angular-Electron-Sequelize TypeError:无法读取未定义的属性“替换”

时间:2019-11-14 05:50:47

标签: angular electron sequelize.js

我正在开发一个Angular-Electron-Sequelize应用程序,该应用程序允许我从数据库表中读取日志。但是,调用Sequelize构造函数时,出现错误“无法读取未定义的属性'replace'”。我检查了几篇文章,但还没有找到与我的匹配的问题/解决方案。

在我的代码中断的地方,它正在将用户定义的连接对象传递给Angular服务,该服务处理(通过Sequelize)伸向数据库。

// Function in a larger class...
loadLogBase(connection: { database: string; hostname: string; authentication: object; options: object; }) {
    const sequelizeOpts: Options = {
      dialect: 'mssql',
      host: connection.hostname,
      dialectOptions: {
        authentication: connection.authentication,
        options: connection.options
      }
    };

    // sequelize is being loaded in a core service with other NodeJS modules,
    // but the call is still directly at the sequelize constructor.
    // The error is being thrown from the following constructor call:
    const sequelize = new this.electron.sequelize.Sequelize(
      connection.database,
      sequelizeOpts);
    setup_model(sequelize);

    LogEntry.findAll().then(entries => {
      this._log.next(entries); // pass found entries to RxJS Subject
    });
}

但是,在应用程序中,出现以下错误/跟踪:

main-es2015.c5a71ce90e126b766877.js:65099 ERROR TypeError: Cannot read property 'replace' of null
    at new Sequelize (path\to\node_modules\sequelize\lib\sequelize.js:189)
    at LogService.loadLogBase (main-es2015.c5a71ce90e126b766877.js:251554)
    at LogDockComponent.refreshLog (main-es2015.c5a71ce90e126b766877.js:251649)
    at SafeSubscriber._next (main-es2015.c5a71ce90e126b766877.js:251675)
    at SafeSubscriber.__tryOrUnsub (main-es2015.c5a71ce90e126b766877.js:199512)
    at SafeSubscriber.next (main-es2015.c5a71ce90e126b766877.js:199451)
    at Subscriber._next (main-es2015.c5a71ce90e126b766877.js:199401)
    at Subscriber.next (main-es2015.c5a71ce90e126b766877.js:199378)
    at BehaviorSubject._subscribe (main-es2015.c5a71ce90e126b766877.js:198629)
    at BehaviorSubject._trySubscribe (main-es2015.c5a71ce90e126b766877.js:198834)
    at BehaviorSubject._trySubscribe (main-es2015.c5a71ce90e126b766877.js:199206)
    at BehaviorSubject.subscribe (main-es2015.c5a71ce90e126b766877.js:198820)
    at LogDockComponent.ngOnInit (main-es2015.c5a71ce90e126b766877.js:251666)
    at checkAndUpdateDirectiveInline (main-es2015.c5a71ce90e126b766877.js:87989)
    at checkAndUpdateNodeInline (main-es2015.c5a71ce90e126b766877.js:99323)
    at checkAndUpdateNode (main-es2015.c5a71ce90e126b766877.js:99262)
    at debugCheckAndUpdateNode (main-es2015.c5a71ce90e126b766877.js:100284)
    at debugCheckDirectivesFn (main-es2015.c5a71ce90e126b766877.js:100227)
    at Object.eval [as updateDirectives] (LogDockComponent_Host.ngfactory.js? [sm]:1)
    at Object.debugUpdateDirectives [as updateDirectives] (main-es2015.c5a71ce90e126b766877.js:100215)
    at checkAndUpdateView (main-es2015.c5a71ce90e126b766877.js:99227)
    at callViewAction (main-es2015.c5a71ce90e126b766877.js:99593)
    at execEmbeddedViewsAction (main-es2015.c5a71ce90e126b766877.js:99550)
    at checkAndUpdateView (main-es2015.c5a71ce90e126b766877.js:99228)
    at callViewAction (main-es2015.c5a71ce90e126b766877.js:99593)
    at execComponentViewsAction (main-es2015.c5a71ce90e126b766877.js:99521)
    at checkAndUpdateView (main-es2015.c5a71ce90e126b766877.js:99234)
    at callViewAction (main-es2015.c5a71ce90e126b766877.js:99593)
    at execEmbeddedViewsAction (main-es2015.c5a71ce90e126b766877.js:99550)
    at checkAndUpdateView (main-es2015.c5a71ce90e126b766877.js:99228)
    at callViewAction (main-es2015.c5a71ce90e126b766877.js:99593)
    at execEmbeddedViewsAction (main-es2015.c5a71ce90e126b766877.js:99550)
    at checkAndUpdateView (main-es2015.c5a71ce90e126b766877.js:99228)
    at callViewAction (main-es2015.c5a71ce90e126b766877.js:99593)

在运行Chrome调试器时,我在代码的以下位置看到了Sequelize构造函数中抛出的错误:

      const urlParts = url.parse(arguments[0], true);
      options.dialect = urlParts.protocol.replace(/:$/, ''); // <-- throw error here

我认为这是因为arguments[0]试图从connection.database参数而不是实际URL读取。设置断点后,我会看到此行为。但是,我不确定Sequelize是否应该注意到传入的选项并从那里检查主机。

0 个答案:

没有答案