function-plot icon indicating copy to clipboard operation
function-plot copied to clipboard

Production errors with Svelte

Open stephenlrandall opened this issue 3 years ago • 4 comments

I'm attempting to use this library with Svelte(Kit). In development, I immediately run into a pair of solvable issues:

  • global is not defined -- Either set global = window in a <svelte:head> tag, or set define: { global: "window" } in the Vite config file
  • Module "events" has been externalized for ... -- Separately install the "events" package.

Everything then works in development mode (although it would be nice if these were fixed at the function-plot level).

In production mode, I'm running into an unavoidable Attempting to define property on object that is not extensible. error. Digging into the Svelte output, the specific line it's complaining about is:

var out2 = Object.assign(relational, arithmetic, algebra, trigonometric);

since relational is defined (not sure in which dependency...) as:

const relational = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
...
}, Symbol.toStringTag, { value: "Module" }));

So the issue is the Object.freeze call on something that's later a target in Object.assign. (If I remove the Object.freeze call on relational in the built output, everything works fine.) Where is this coming from, and is there a way that this issue can be addressed?

stephenlrandall avatar Jul 15 '22 13:07 stephenlrandall

Thanks for the report, the library that's doing:

var out2 = Object.assign(relational, arithmetic, algebra, trigonometric);

is https://github.com/mauriciopoppe/interval-arithmetic/blob/fce59e39f08a18bedbd7ff1d8a2ae2bf39ad9039/src/index.ts#L20-L22, I think I did it because of a limitation of Typescript with the number of args sent to Object.assign, I think I'll add ts-ignore and check that the docs are still generated correctly

mauriciopoppe avatar Jul 15 '22 17:07 mauriciopoppe

Could you just spread the objects instead?

const out = { ..._Interval, ...constants, ...round, ... };

stephenlrandall avatar Jul 15 '22 19:07 stephenlrandall

Thanks for the suggestion, I'll try that and see if the doc generator works with that

mauriciopoppe avatar Jul 15 '22 21:07 mauriciopoppe

I've fixed the issue downstream in https://github.com/mauriciopoppe/interval-arithmetic/releases/tag/v1.0.7 and published [email protected], please try with that prerelease version and let me know how it goes

mauriciopoppe avatar Jul 19 '22 06:07 mauriciopoppe

If this is still an issue feel free to reopen this bug, https://github.com/mauriciopoppe/function-plot/releases/tag/v1.23.0 is already released

mauriciopoppe avatar Oct 17 '22 04:10 mauriciopoppe