revoltchat / revolt.js

Modern Typescript library for interacting with Revolt.
https://revolt.js.org
MIT License
216 stars 54 forks source link

bug: explicitly importing the ESM version fails #83

Closed williamhorning closed 1 month ago

williamhorning commented 1 year ago

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";
  ~~~~~~