vite-plugin-wasm-pack icon indicating copy to clipboard operation
vite-plugin-wasm-pack copied to clipboard

copy crates failed with solidstart/vinxi solution

Open zhengkyl opened this issue 1 year ago • 1 comments

I'm using solid-start and trying to load a local package.

If the node_modules/mypackage folder doesn't exist or it exists but isn't empty, I get the error.

I know this part of the buildStart() hook is where the error happens.

https://github.com/nshen/vite-plugin-wasm-pack/blob/5e626b9d387b9e9df87712479df2eb5110af02f7/src/index.ts#L121-L125

The buildStart() gets called 3 times because vinxi (used by solidstart) starts 3 apps with the same vite config as explained here (https://github.com/nksaraf/vinxi/issues/262#issuecomment-2011412971)

It makes sense that running await fs.copy 3 times at once causes issues. And the comment suggests this as a solution which worked for me.

import { defineConfig } from "@solidjs/start/config";
import wasmpack from "vite-plugin-wasm-pack";

export default defineConfig({
  vite({ router }) {
    return {
      plugins: router === "client" ? [wasmpack("./mypackage")] : []
    }
  }
})

I don't know if this is something this plugin could/should address, but I hope this solution helps someone else.

zhengkyl avatar Jul 10 '24 18:07 zhengkyl

This is also a problem with Vite + the new environments API (such as when using @cloudflare/vite-plugin as it works in a similar way to how Vinxi works.

oscartbeaumont avatar Feb 10 '25 23:02 oscartbeaumont