javascriptnode.jsvoximplant

What is the correct way to instantiate the client object? TypeError: VoximplantApiClient is not a constructor


What is the correct way to instantiate the client object? it give me this error when i try to const client = new VoximplantApiClient(); TypeError: VoximplantApiClient is not a constructor

Can i get a ES6 imports code example? docs have old require imports This is how i am importing in my nodejs: import VoximplantApiClient from '@voximplant/apiclient-nodejs'

docs: https://voximplant.com/docs/references/httpapi/users#adduser

When i do this iimport { VoximplantApiClient } from '@voximplant/apiclient-nodejs'; i get

import { VoximplantApiClient } from '@voximplant/apiclient-nodejs';
         ^^^^^^^^^^^^^^^^^^^
SyntaxError: Named export 'VoximplantApiClient' not found. The requested module '@voximplant/apiclient-nodejs' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@voximplant/apiclient-nodejs';
const { VoximplantApiClient } = pkg;

Solution

  • The issue is how ES6 modules are emulated in CommonJS.

    In order for the node.js modules to work correctly, use the following construction:

    import VoximplantApiClient from '@voximplant/apiclient-nodejs';
    const client = new VoximplantApiClient.default('/path/to/credentials.json');