0

This is my first time using js so bear with me (I’m an experienced python programmer).

How am I supposed to use this repo in js: https://github.com/omerdn1/otter.ai-api

I installed the package with npm and created the setup script (and updated it to fit my login info), but I’m getting a SyntaxError: SyntaxError: Cannot use import statement outside a module at the first line import OtterApi from 'otter.ai-api';.

I looked at the similar SO questions (1 and 2) and the solution seems to be adding ”type”: “module” to the package.json file. But 1) I’m not sure if they actually me “module” or its a specific module name 2) I tried this with both “module” and “OtterApi” and I’m still getting the SyntaxError.

I’m totally lost. Don’t know how modules work in js. Would greatly appreciate your help. :)

Edit: I replaced the import with the following instead: const OtterApi = require('otter.ai-api')

This seems to work as the initial error is no longer there. However, I’m now getting a separate SyntaxError (which is may be unrelated to the first error?): SyntaxError: await is only valid in async functions and the top level bodies of modules.

This is from the following code:

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

const otterApi = new OtterApi({
  email: 'email@example.com', // Your otter.ai email
  password: 'abc123!#', // Your otter.ai password
});

await otterApi.init() // Performs login

The error happens at the last line.

Jacques Thibodeau
  • 859
  • 1
  • 8
  • 21

1 Answers1

0

I used the setup code, but I replaced the import with the following instead: const OtterApi = require('otter.ai-api').

Apparently, you can’t use ES Modules in Node without jumping through some hoops (or maybe using the latest version?). So, the above resolves that issue.

Jacques Thibodeau
  • 859
  • 1
  • 8
  • 21
  • 1
    There's no "hoops", you just can't freely mix and match ESM and CJS. They're different formats and need to be treated as such. `"type": "module"` in your `package.json` signals to Node which format `.js` should be treated as. By default, it's CJS, hence your error (using ESM's `import` in CJS), but you can add that field to instead treat `.js` as ESM. There's many articles on this, but do know it's a bit of a pain point at the moment for everyone. – rschristian May 10 '22 at 04:45
  • @rschristian Ah! You're right. I think initially my issue was related to my node version so `"type": "module"` was not working. Or I didn't have the code in the right place. Anyways, I added it now and the import works, thanks! – Jacques Thibodeau May 10 '22 at 05:01