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

ES Module

Open jcubic opened this issue 3 years ago • 3 comments

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/[email protected]/complex.js";

throws:

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

and

import { Complex } from "https://cdn.jsdelivr.net/npm/[email protected]/complex.js";

throws:

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

and:

import "https://cdn.jsdelivr.net/npm/[email protected]/complex.js";

throws:

Error: Uncaught TypeError: Cannot set properties of undefined (setting 'Complex')

jcubic avatar Dec 19 '22 21:12 jcubic

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

jcubic avatar Dec 19 '22 21:12 jcubic

There is also this option https://cdn.jsdelivr.net/npm/[email protected]/complex.js/+esm

jimaek avatar Dec 20 '22 09:12 jimaek

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

othelarian avatar Dec 30 '22 09:12 othelarian