infusion / Complex.js

Complex.js is a com numbers library written in JavaScript
https://raw.org/article/complex-numbers-in-javascript/
MIT License
232 stars 33 forks source link

ES Module #42

Open jcubic opened 1 year ago

jcubic commented 1 year ago

I'm trying to this package as ES Module, even that it has some code:

Object.defineProperty(Complex, "__esModule", { 'value': true });

ES Modules don't work from the browser.

import Complex from "https://cdn.jsdelivr.net/npm/complex.js@2.1.1/complex.js";

throws:

Error: Uncaught SyntaxError: The requested module 'https://cdn.jsdelivr.net/npm/complex.js@2.1.1/complex.js' does not provide an export named 'default'

and

import { Complex } from "https://cdn.jsdelivr.net/npm/complex.js@2.1.1/complex.js";

throws:

Error: Uncaught SyntaxError: The requested module 'https://cdn.jsdelivr.net/npm/complex.js@2.1.1/complex.js' does not provide an export named 'Complex'

and:

import "https://cdn.jsdelivr.net/npm/complex.js@2.1.1/complex.js";

throws:

Error: Uncaught TypeError: Cannot set properties of undefined (setting 'Complex')
jcubic commented 1 year ago

Just found out about skypack you can add this to the README. To import the library in ES Module you can use this:

import Complex from "https://cdn.skypack.dev/complex.js";
jimaek commented 1 year ago

There is also this option https://cdn.jsdelivr.net/npm/complex.js@2.1.1/complex.js/+esm

othelarian commented 1 year ago

This issue has an impact on other ES modules which use complex.js (in my case @dice-roller/rpg-dice-roller).