简体   繁体   English

TypeError: obj is not a constructor (js / node 错误)

[英]TypeError: obj is not a constructor (error in js / node)

Note: I'm normally coding in Python, so I am completely new to javascript.注意:我通常在 Python 中编码,所以我对 javascript 完全陌生。

I'm trying to use the following repo: https://github.com/omerdn1/otter.ai-api我正在尝试使用以下存储库: https://github.com/omerdn1/otter.ai-api

I used the setup code, but I replaced the import with the following instead: const OtterApi = require('otter.ai-api') because I was getting SyntaxError: Cannot use import statement outside a module .我使用了设置代码,但我用以下代码替换了导入: const OtterApi = require('otter.ai-api')因为我得到SyntaxError: Cannot use import statement outside a module

However, now I'm getting the following error: TypeError: OtterApi is not a constructor .但是,现在我收到以下错误: TypeError: OtterApi is not a constructor If I look at index.js in the repo, it does look like a constructor?如果我查看 repo 中的 index.js,它看起来确实像一个构造函数? First part of the code is:代码的第一部分是:

class OtterApi {
  constructor(options = {}) {
    this.options = options;
    this.user = {};
    this.csrfToken = '';
  }

  init = async () => {
    await this.#login();
  };

The code I'm trying to run:我试图运行的代码:

const OtterApi = require('otter.ai-api');

const otterApi = new OtterApi({
    email: 'email', // Your otter.ai email
    password: 'pw', // Your otter.ai password
});

async function main() {
    await otterApi.init() // Performs login
}

main();

I get the error when using new OtterApi() .使用new OtterApi()时出现错误。 I'm not sure how to resolve this.我不确定如何解决这个问题。

You need to refer to the "default" export:您需要参考“默认”导出:

const OtterApi = require('otter.ai-api').default;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM