revolt.js icon indicating copy to clipboard operation
revolt.js copied to clipboard

bug: explicitly importing the ESM version fails

Open williamhorning opened this issue 2 years ago • 0 comments

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:[email protected]/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/[email protected]/node_modules/revolt.js/lib/esm/index.js:1:1

  export * from "./classes";
  ~~~~~~

williamhorning avatar Jul 02 '23 14:07 williamhorning