Registry / testing / webgpujs

webgpujs

JSON →
library0.0.30jsnpmunverified

WebGPUjs (v0.0.30) is a JavaScript library that enables writing full-featured WGSL pipelines directly in JavaScript, without requiring separate shader files. It provides a high-level API for allocating buffers, uniforms, textures, and specifying compute, vertex, and fragment shaders. Key features include automatic binding combination, support for compute shaders with multiple output buffers, chaining of shader stages, and instance VBOs. As an early-stage project (pre-v1), it breaks often and lacks comprehensive docs. It competes with raw WebGPU API and wgpu-native bindings, focusing on developer ergonomics for rapid prototyping. Release cadence is irregular; expect breaking changes.

npm install webgpujs
INSTALL
IMPORT
SIG · WEBGPUJS
W
webgpujs
testingjavascriptv0.0.30
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GPU
import { GPU } from 'webgpujs'
const GPU = require('webgpujs')
ESM-only; package does not support CommonJS require. TypeScript types included.
ComputePipeline
import { ComputePipeline } from 'webgpujs'
import { computePipeline } from 'webgpujs'
Exported class names are PascalCase. Lowercase import will fail.
TranspileWGSL
import { TranspileWGSL } from 'webgpujs'
Utility for converting JS-like WGSL syntax; not always needed.
type ComputePipelineOptions
import type { ComputePipelineOptions } from 'webgpujs'
import { ComputePipelineOptions } from 'webgpujs'
Interface only; use type import to avoid runtime import errors.

Creates a WebGPU compute pipeline that doubles each element of a 1024-element float32 array using a WGSL shader.

import { GPU, ComputePipeline, Buffer } from 'webgpujs'; async function run() { const gpu = await GPU.create(); const pipeline = new ComputePipeline(gpu, { code: ` @group(0) @binding(0) var<storage, read_write> data: array<f32>; @compute @workgroup_size(64) fn main(@builtin(global_invocation_id) id: vec3<u32>) { data[id.x] = data[id.x] * 2.0; } `, buffers: [{ name: 'data', size: 1024 * 4 }], workgroupCount: [16, 1, 1], }); const data = new Float32Array(1024); data.forEach((_, i) => data[i] = i); const buffer = await pipeline.run({ data: data }); await gpu.dispatch(pipeline); const result = await buffer.read(); console.log('Result:', result); } run().catch(console.error);
Debug
Known issues
breakingGPU.create() was previously synchronous; now returns a Promise.
fix
Use await GPU.create() or .then().
affects: >=0.0.20
deprecatedBuffer type strings (e.g., 'storage') replaced with buffer descriptor objects.
fix
Replace buffer type strings with { type: 'storage', ... }.
affects: >=0.0.25
breakingpipeline.run() no longer returns a buffer array; returns a single buffer object.
fix
Access result via .read() on the returned buffer.
affects: >=0.0.28
gotchaWGSL shader code must be inside compute shader functions; bare code not supported.
fix
Wrap code in an entry point function (e.g., @compute @workgroup_size(64) fn main(...)).
affects: all
gotchaBuffer size must be aligned to 4 bytes (f32). Unaligned sizes cause errors.
fix
Ensure buffer sizes are multiples of 4.
affects: all
Errors
Common errors & fixes
TypeError: GPU.create is not a constructor
Using 'new GPU.create()' instead of 'GPU.create()' (static method).
fix
Replace with 'const gpu = await GPU.create();'
TypeError: Cannot read properties of undefined (reading 'read')
pipeline.run() returns undefined if pipeline is not properly configured or if WebGPU device is lost.
fix
Check that pipeline code is valid and that GPU device is still available.
WGSL syntax error: expected 'fn' keyword
Missing function declaration in shader string.
fix
Wrap your compute logic in a function with @compute attribute.
Error: Requested device adapter not found
No WebGPU-compatible GPU or browser not supporting WebGPU.
fix
Run in a recent Chrome/Edge or Firefox nightly; ensure WebGPU enabled.
Upgrade
Version history
0.0.30latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
Amazon
1
Resources
webgpujs — npm install webgpujs · libregistry