cortex-js / compute-engine

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

Webpack 4 import fails #78

Closed RafalDardzinski closed 1 year ago

RafalDardzinski commented 1 year ago

I'm using webpack@4.46.0 along with typescript@4.9.5 . I'm trying to use @cortex-js/compute-engine@0.12.2. When I try to import ComputeEngine according to the documentation... import { ComputeEngine } from "@cortex-js/compute-engine/dist/compute-engine.min"

...I get an error on build: ERROR in ./node_modules/@cortex-js/compute-engine/dist/compute-engine.min.js 2:42147 Module parse failed: Unexpected token (2:42147) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders | /** CortexJS Compute Engine 0.12.2 */

I thought it's something with my webpack config, but the problem also occurs on newly setup project with basic webpack configuration that supports typescript. On the side-note, importing mathlive works fine.

kobelinh24 commented 1 year ago

I'm trying to do import '@cortex-js/compute-engine'; while building a web component, also got the same error while compiling: ../node_modules/@cortex-js/compute-engine/dist/compute-engine.min.esm.js 2:42173 Module parse failed: Unexpected token (2:42173) You may need an appropriate loader to handle this file type.

Mathlive indeed works as indicated.

Any update on this as this long-opened issue?

arnog commented 1 year ago

I haven't investigated this issue. It would help if someone could provide code that reproduces the problem.

That said, I suspect it's related to the fact that Webpack 4 does not support optional chaining (the ?. operator). Webpack 5 should support it, though.

See https://github.com/webpack/webpack/issues/10227#issuecomment-642734920 for a discussion on a possible workaround.