NodeJS 示例化客户端对象的正确方法是什么?TypeError:VoximplantApiClient不是构造函数

nwo49xxi  于 2023-06-05  发布在  Node.js
关注(0)|答案(1)|浏览(133)

示例化客户端对象的正确方法是什么?它给予我这个错误,当我尝试const client = new VoximplantApiClient(); TypeError: VoximplantApiClient is not a constructor
我可以得到一个ES6导入代码示例吗?docs有旧的require imports这是我在nodejs中导入的方式:从'@voximplant/apiclient-nodejs'导入VoximplantApiClient
文档:https://voximplant.com/docs/references/httpapi/users#adduser
当我这样做时,我得到import { VoximplantApiClient } from '@voximplant/apiclient-nodejs';

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;
wkyowqbh

wkyowqbh1#

问题是如何在CommonJS中模拟ES6模块。
为了让node.js模块正常工作,请使用以下结构:

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

相关问题