The `webgpu` package provides a native WebGPU implementation for Node.js, leveraging Google's Dawn project. Currently at version 0.4.0, it sees frequent minor updates, aligning with the ongoing development of the WebGPU standard and Dawn itself. Its primary purpose is to enable server-side GPU computation and rendering without a browser environment, allowing developers to execute WGSL shaders and manage GPU resources directly within Node.js applications. A key differentiator is its direct integration with native GPU drivers via Dawn, contrasting with browser-based WebGPU which runs within a web page context. It is not intended for testing web pages or providing web platform APIs like canvas or video elements, but rather for headless GPU operations such as rendering to textures and running compute shaders.
npm install webgpuVerified import paths — ran on the pinned version, not inferred.
This quickstart initializes a WebGPU context in Node.js, obtains a GPU adapter and device, and demonstrates creating a simple GPU buffer. It highlights the use of `create` and `globals` and the typical setup flow for headless WebGPU operations.
Explicitly remove the global reference to the `GPU` object (e.g., `delete globalThis.navigator`) when WebGPU resources are no longer needed to allow the Node.js process to terminate.
For testing WebGPU in a browser context, tools like Puppeteer are recommended. This package is designed for server-side, off-screen GPU computation.
Consult the project's README for links to the appropriate issue trackers (e.g., Chromium issue tracker for Dawn/WebGPU bugs).
Review the error messages for available backends and adapters, then update the `create()` options with a valid string from the list. Alternatively, omit `backend` or `adapter` to let Dawn select defaults.
Pin exact package versions (`npm install --save-exact webgpu`) and thoroughly test when updating. Consult the Dawn and WebGPU specification changelogs for anticipated API shifts.
Provide a valid backend name from the list printed in the error message, or omit the `backend` option to let Dawn select an appropriate one automatically for the current system.
Use one of the `name` values from the `Available adapters:` list in your `create([])` call, or rely on `navigator.gpu.requestAdapter()` with `powerPreference` for adapter selection.
Explicitly remove the global reference to the WebGPU object (e.g., `delete globalThis.navigator`) once all GPU operations are complete and the context is no longer needed.