ThatOpen / engine_web-ifc

Reading and writing IFC files with Javascript, at native speeds.
https://thatopen.github.io/engine_web-ifc/demo
Mozilla Public License 2.0
577 stars 170 forks source link

[Bug]: Vite/vue3 wasm issue #809

Closed blahmonkey closed 2 months ago

blahmonkey commented 2 months ago

What happened?

Just a basic vite/vue3 app in dev server, trying this code.

      import * as WebIFC from '../node_modules/web-ifc/web-ifc-api.js'

... (in mounted hook) ...
      // initialize the API
      const ifcApi = new WebIFC.IfcAPI()

      // initialize the library
      await ifcApi.Init()

I get this console error related to mime types. Obviously the web-ifc code fails here (more console errors ensue)

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

I looked into it and I saw that the web-ifc-api.js is trying to do a fetch on web-ifc.wasm using the url`/web-ifc.wasm' which obviously won't give any result since the wasm file is inside the node_nodules/web-ifc folder.

Thoughts on what is wrong? Integrating web-ifc as an npm module into vue3/other framework apps is obviously a key use case for end users. Production build doesnt work either, same issue.

Version

0.0.54

What browsers are you seeing the problem on?

Chrome

Relevant log output

App.vue:30 wasm streaming compile failed: TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'.

Anything else?

image image
blahmonkey commented 2 months ago

I seem to have got it working using this workaround (I used the public folder not assets) https://stackoverflow.com/questions/71571129/how-to-use-embedded-webassembly-in-vite