Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

globals is not exported in type definition #1

Open
6XGate opened this issue Feb 9, 2025 · 2 comments
Open

globals is not exported in type definition #1

6XGate opened this issue Feb 9, 2025 · 2 comments

Comments

@6XGate
Copy link

6XGate commented Feb 9, 2025

Trying to import global from webgpu results in a compiler error in TypeScript: TS2305: Module '"webgpu"' has no exported member 'globals'..

@greggman
Copy link
Collaborator

greggman commented Feb 9, 2025

does v0.0.27 work ?

@greggman
Copy link
Collaborator

I'm not sure your use case but v0.0.28 works

package.json

{
  "name": "webgpu-test",
  "version": "1.0.0",
  "main": "index.js",
  "type": "module",
  "license": "ISC",
  "dependencies": {
    "webgpu": "^0.2.8"
  },
  "devDependencies": {
    "typescript": "^5.7.3"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "strict": true,
    "target": "ESNext",
    "lib": ["DOM", "ESNext"]
  }
}

example.ts

import { create, globals } from 'webgpu';

Object.assign(globalThis, globals);

async function main() {
  const navigator = { gpu: create([]) };
  const adapter = await navigator.gpu.requestAdapter();
  if (!adapter) {
    return;
  }

  // do some webgpu
  const device = await adapter.requestDevice();
  const texture = device.createTexture({
    usage: GPUTextureUsage.TEXTURE_BINDING,
    size: [2],
    format: 'r16float',
  });

  texture.destroy();
  device.destroy();

  await new Promise(r => setTimeout(r, 1000));
}

main();
./node_modules/.bin/tsc
node example.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants