cortex-js / compute-engine

An engine for symbolic manipulation and numeric evaluation of math formulas expressed with MathJSON
https://cortexjs.io
MIT License
357 stars 42 forks source link

NetxJS Webpack bundling fails in 0.17.0 #123

Closed volesen closed 11 months ago

volesen commented 11 months ago

I have proposed a fix in #124.

Description

NextJS 13.5.4 fails to bundle @cortex-js/compute-engine. It tries to bundle a cjs file as an esm module, resulting in a missing constructor for ComputeEngine.

Steps to Reproduce

A minimal example to reproduce the issues can be found on StackBlitz.

Actual Behavior

The following error message occurs in the associated minimal example.

Attempted import error: 'ComputeEngine' is not exported from '@cortex-js/compute-engine' (imported as 'ComputeEngine').

Import trace for requested module:
./src/app/exercises/calculus/[seed]/page.tsx
 ⨯ src/app/exercises/calculus/[seed]/page.tsx (33:15) @ eval
 ⨯ TypeError: _cortex_js_compute_engine__WEBPACK_IMPORTED_MODULE_5__.ComputeEngine is not a constructor
    at eval (./src/app/exercises/calculus/[seed]/page.tsx:43:20)
    at Exercise (./src/app/exercises/calculus/[seed]/page.tsx:42:70)
  31 | 
  32 |   const polynomial = useMemo(() => {
> 33 |     const ce = new ComputeEngine();
     |               ^
  34 | 
  35 |     return ce.box([
  36 |       "Add",

Expected Behavior

I would expect Webpack to only exclusively import the cjs or esm files.

Environment

MathLive version 0.17.0

Operating System macOS

Browser Safari

NextJS 13.5.4

volesen commented 11 months ago

Fixed in v0.18.0