-
Notifications
You must be signed in to change notification settings - Fork 28.9k
Description
What version of Next.js are you using?
10.0.7
What version of Node.js are you using?
v14.3.0
What browser are you using?
N/A
What operating system are you using?
Ubuntu 20.04
How are you deploying your application?
N/A
Describe the Bug
I took the with-webassembly example and moved the loading and execution of wasm into a web worker (to simulate offloading of expensive functions to wasm in another thread). Unfortunately I receive the following error for both next dev
and next build
Failed to compile.
webpack/runtime/compat
The "path" argument must be of type string. Received undefined
Which I have been unable to debug.
The project is straightforward (no additional dependencies, just plain next.js) but I'll copy the relevant bits here for posterity:
worker.js
onmessage = async function (e) {
const rustModule = await import("../add.wasm");
console.log(rustModule.add_one(10));
};
index.js
import { useEffect, useRef } from "react";
const Page = () => {
const workerRef = useRef();
useEffect(() => {
if (workerRef.current === undefined) {
workerRef.current = new Worker(new URL("./worker.js", import.meta.url));
}
}, []);
return (
<button onClick={() => workerRef.current.postMessage([])}>Click</button>
);
};
export default Page;
One very important bit is that this is a webpack 5 project as webpack 5 supports web workers and wasm natively (albeit experimentally) and I've been unable to get webpack 4 working with the appropriate plugins due to #21679 .
Wasm files outside of web workers work, and web workers without wasm work, the combination of them seems to give rise to the error. It doesn't matter where the wasm module is imported in the web worker or even if it is dynamically imported or not.
Expected Behavior
For the project to be built
To Reproduce
I've created a bug repro: https://github.com/nickbabcock/next.js-wasm-worker
clone, install, and build to repro the error.