Tools
Tools copied to clipboard
feat: Support for ESM
Can we add support for ESM for agora-token?
ECMAScript modules are the official standard format to package JavaScript code for reuse. Modules are defined using a variety of import and export statements.
Node.js fully supports ECMAScript modules as they are currently specified and provides interoperability between them and its original module format, CommonJS.
Newer build tools like Vite expect libraries to support ESM exports. Not having ESM and only exporting to CJS, needs a workaround to use the library like so:
import TokenServerImport from 'agora-token';
const { RtcRole, RtcTokenBuilder } = TokenServerImport; // CJS module import
Using a named import from the package might work in dev, but would break in production builds:
Hey @plutoless what are your thoughts?
@EkaanshArora Set the type of package.json to module, and try again