framework icon indicating copy to clipboard operation
framework copied to clipboard

Import wasm bug when running on production (nuxt preview)

Open bitlands opened this issue 3 years ago • 5 comments

Environment


  • Operating System: Darwin
  • Node Version: v18.9.0
  • Nuxt Version: 3.0.0-rc.10
  • Nitro Version: 0.5.3
  • Package Manager: [email protected]
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-2ebtve-l73ttp?file=nuxt.config.ts

I cannot reproduce it on stackblitz because Nuxt is not running in production there. That's why I've created a repository with a minimal example of the problem here https://github.com/bitlands/wasm-import

Describe the bug

This bug is a follow up thing of https://github.com/nuxt/framework/issues/6703. When I run yarn dev everything works fine and the library can be loaded but when I run yarn run build & yarn run preview the following error appears when I go to the browser console at localhost:3000.

Uncaught (in promise) CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 3c 21 44 4f @+0
image

Additional context

Thanks for any help!

Logs

No response

bitlands avatar Sep 18 '22 16:09 bitlands

See this: https://v3.nuxtjs.org/examples/experimental/wasm#wasm

HomWang avatar Sep 19 '22 08:09 HomWang

@516310460 It's basically adding:

export default defineNuxtConfig({
  nitro: {
    experimental: {
      wasm: true
    }
  },
...

to the nuxt.config.ts right? Unfortunately this produces a new error when I run yarn run build > yarn run preview and go to localhost:3000.

Unhandled Promise Rejection: CompileError: WebAssembly.Module doesn't parse at byte 0: module doesn't start with '\0asm'
image

bitlands avatar Sep 19 '22 08:09 bitlands

@516310460 As a reminder: I use the wasm package for the client not for the server

bitlands avatar Sep 19 '22 08:09 bitlands

FYI, you can hit Ctrl-C to stop the dev server in stackblitz and then run npm run build && node .output/server/index.mjs (or hard-code that as the dev command in package.json) to reproduce within stackblitz alone in future issues.

danielroe avatar Sep 19 '22 08:09 danielroe

@danielroe Thanks for the tip! With that I can also reproduce it in stackblitz image

bitlands avatar Sep 19 '22 19:09 bitlands

@danielroe Any updates or things I could test? I'm not really sure if this is an issue on my side or in Nuxt

bitlands avatar Sep 27 '22 10:09 bitlands

@danielroe Thank you for considering this issue. In my opinion this is not a minor bug because it means that as long as this one is not fixed .wasm packages cannot be used with Nuxt 3 but I trust in your evaluation. Thank you!

chrizcros avatar Nov 01 '22 09:11 chrizcros

@danielroe Thank you for considering this issue. In my opinion this is not a minor bug because it means that as long as this one is not fixed .wasm packages cannot be used with Nuxt 3 but I trust in your evaluation. Thank you!

Please be aware that this categorization follows a flow chart. See the docs for more

TheAlexLichter avatar Nov 02 '22 11:11 TheAlexLichter