PaddiM8 / kalker

Scientific calculator with math syntax that supports user-defined variables and functions, complex numbers, and estimation of derivatives and integrals
https://kalker.xyz
MIT License
1.59k stars 70 forks source link

kalk-component: Failed to execute 'compile' on 'WebAssembly' #91

Open BearToCode opened 2 years ago

BearToCode commented 2 years ago

Hello, I'm trying to include the Kalk web component in a Tauri app with a React front-end. However, I keep getting the following error, which comes directly from the component bundle.js:

TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'.

That's how I included Kalk:

import { KalkCalculator, ConsoleLine } from "@paddim8/kalk-component";

const ToolsWindow = () => {
  return (
      <div className="kalk">
        <kalk-calculator>
          <console-line>kalker</console-line>
          <console-line>
            <span className="hint">Type 'help' for instructions.</span>
          </console-line>
        </kalk-calculator>
      </div>
  )
}

My project.json looks like that

"dependencies": {
    "@paddim8/kalk-component": "^2.0.0",
    "@tauri-apps/api": "^1.0.0-rc.6",
    "react": "^18.1.0",
    "react-dom": "^18.1.0",
    "react-scripts": "5.0.1",
    ...
  },

Your work is really cool and I'd really like to use it in my project.

PaddiM8 commented 2 years ago

Hmm that's strange. Perhaps something you're using doesn't support WebAssembly? What bundler are you using?

BearToCode commented 2 years ago

I've not installed any bundler, there should only be a Tauri Bundler for the Rust side of the app (at least that's what I understood reading the documentation).

BearToCode commented 2 years ago

I've looked for help on the Tauri community and they sent me what should be a list of mime types: https://github.com/tauri-apps/tauri/blob/dev/core/tauri-runtime/src/http/mime_type.rs

If yours is not in the list I can file an issue on their side.

Also: do I need Webpack and Svelte to use the module?

PaddiM8 commented 2 years ago

Aha I see. I guess missing support for the mime type could be it, since I haven't seen that error in other situations. You shouldn't need Webpack or Svelte to use the module. The website (kalker.xyz) doesn't use anything like that! The library should basically just provide a regular web component.

BearToCode commented 2 years ago

Apparently there are ways to import the .wasm that do not check for the mime type:

https://stackoverflow.com/a/52732108/14065064

If you considered applying that change it would be great.