bug: explicitly importing the ESM version fails #30

Closed
opened 2026-02-16 12:26:49 -05:00 by yindo · 0 comments
Owner

Originally created by @williamhorning on GitHub (Jul 2, 2023).

What happened?

When importing revolt.js' ESM version directly from revolt.js/lib/esm/index.js, an error is thrown because it's interpreted as a CJS module by both Node and Deno.

How to reproduce:

import { Client } from "revolt.js/lib/esm/index.js";
// or "npm:revolt.js@7.0.0-beta.7/lib/esm/index.js" when using Deno

const bot = new Client();

Logs:

file:///home/jersey/projects/revolt-repro/index.js:1
import { Client } from "revolt.js/lib/esm/index.js";
         ^^^^^^
SyntaxError: Named export 'Client' not found. The requested module 'revolt.js/lib/esm/index.js' 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 'revolt.js/lib/esm/index.js';
const { Client } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:189:5)

Node.js v19.8.1
error: 'import', and 'export' cannot be used outside of module code at file:///home/jersey/projects/revolt-repro/node_modules/.deno/revolt.js@7.0.0-beta.9/node_modules/revolt.js/lib/esm/index.js:1:1

  export * from "./classes";
  ~~~~~~
Originally created by @williamhorning on GitHub (Jul 2, 2023). ### What happened? When importing revolt.js' ESM version directly from `revolt.js/lib/esm/index.js`, an error is thrown because it's interpreted as a CJS module by both Node and Deno. **How to reproduce:** ```ts import { Client } from "revolt.js/lib/esm/index.js"; // or "npm:revolt.js@7.0.0-beta.7/lib/esm/index.js" when using Deno const bot = new Client(); ``` **Logs:** ``` file:///home/jersey/projects/revolt-repro/index.js:1 import { Client } from "revolt.js/lib/esm/index.js"; ^^^^^^ SyntaxError: Named export 'Client' not found. The requested module 'revolt.js/lib/esm/index.js' 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 'revolt.js/lib/esm/index.js'; const { Client } = pkg; at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21) at async ModuleJob.run (node:internal/modules/esm/module_job:189:5) Node.js v19.8.1 ``` ``` error: 'import', and 'export' cannot be used outside of module code at file:///home/jersey/projects/revolt-repro/node_modules/.deno/revolt.js@7.0.0-beta.9/node_modules/revolt.js/lib/esm/index.js:1:1 export * from "./classes"; ~~~~~~ ```
yindo added the bug label 2026-02-16 12:26:49 -05:00
yindo closed this issue 2026-02-16 12:26:49 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: stoatchat/javascript-client-sdk#30