You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importReact,{useEffect,useState}from"react";importlogofrom"./logo.svg";import"./App.css";importinit,{greet}from"test-wasm";importtype{hello}from"./hello.worker";importHelloWorkerfrom"./hello.worker?worker";import{wrap}from"comlink";functionApp(){const[count,setCount]=useState(0);useEffect(()=>{init().then(async(wasm)=>{constwasmHello=wrap<typeofhello>(newHelloWorker());console.log(awaitwasmHello());console.log(awaitwasmHello());});},[]);return(<divclassName="App"><headerclassName="App-header"><imgsrc={logo}className="App-logo"alt="logo"/><p>HelloWebAssembly!</p><p>Vite+Rust+React</p><p><buttononClick={()=>greet()}>hellowasm</button>{" "}<buttontype="button"onClick={()=>setCount((count)=>count+1)}>count is: {count}</button></p><p>Edit<code>App.tsx</code> and save to test HMR updates.</p><p><aclassName="App-link"href="https://reactjs.org"target="_blank"rel="noopener noreferrer">LearnReact</a>
{" | "}<aclassName="App-link"href="https://vitejs.dev/guide/features.html"target="_blank"rel="noopener noreferrer">ViteDocs</a>
{" | "}<aclassName="App-link"href="https://github.com/lencx/vite-plugin-rsw"target="_blank"rel="noopener noreferrer">RswDocs</a></p></header></div>);}exportdefaultApp;
client error:
Uncaught ReferenceError: HTMLElement is not defined at overlay.ts:118
more:
If you clone test-wasm/pkg to my-app/src/pkg, there will be no error.
import{ ... }from'./WebWorkerImports/Utils'// hack to avoid overlay.ts's dom assumptionsself.HTMLElement=function(){return{}}self.customElements={get(){return[]},}self.onmessage=async(e)=>{
Describe the bug
I used xc-app to create my project.And comlink is installed.But when I run the wasm code in worker, client will report an error.
hello.worker.ts
app.tsx
client error:
Uncaught ReferenceError: HTMLElement is not defined at overlay.ts:118
more:
If you clone
test-wasm/pkg
tomy-app/src/pkg
, there will be no error.hello.worker.ts
I think vitejs/vite#3381 and vitejs/vite#5396 will help you
The text was updated successfully, but these errors were encountered: