Skip to content

fix: Esbuild plugin not working with typescript #2026

@aleksanderkatan

Description

@aleksanderkatan

Using tgpu-unplugin with exbuild does not work. Investigate the problem. You can use the code from #1775. If this is an esbuild issue, create a minimal repro and create an issue.

export async function bundleWithEsbuild(
  entryUrl: URL,
  outDir: URL,
): Promise<URL> {
  const entryFileName = path.basename(entryUrl.pathname, '.ts');
  const outPath = new URL(`${entryFileName}.esbuild.js`, outDir);
  await esbuild({
    plugins: [esbuildPlugin({})],
    entryPoints: [entryUrl.pathname],
    bundle: true,
    outfile: outPath.pathname,
    format: 'esm',
    minify: true,
    treeShaking: true,
  });
  return outPath;
}
pnpm --filter treeshake-test test

> treeshake-test@0.0.0 test /Users/<me>/typepgu-monorepo/apps/treeshake-test
> node index.ts

(node:76259) ExperimentalWarning: Type Stripping is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Starting bundler efficiency measurement...
[unplugin-typegpu] Failed to parse /Users/<me>/typepgu-monorepo/apps/treeshake-test/tests/functionWithUseGpu.ts. Cause: Unexpected token (2:23)
[unplugin-typegpu] Failed to parse /Users/<me>/typepgu-monorepo/packages/typegpu/src/index.ts. Cause: Unexpected token (105:7)
[unplugin-typegpu] Failed to parse /Users/<me>/typepgu-monorepo/packages/typegpu/src/data/index.ts. Cause: Unexpected token (5:14)
[unplugin-typegpu] Failed to parse /Users/<me>/typepgu-monorepo/packages/typegpu/src/data/index.ts. Cause: Unexpected token (5:14)
[unplugin-typegpu] Failed to parse /Users/<me>/typepgu-monorepo/packages/typegpu/src/index.ts. Cause: Unexpected token (105:7)
[unplugin-typegpu] Failed to parse /Users/<me>/typepgu-monorepo/packages/typegpu/src/data/index.ts. Cause: Unexpected token (5:14)
[unplugin-typegpu] Failed to parse /Users/<me>/typepgu-monorepo/packages/typegpu/src/data/index.ts. Cause: Unexpected token (5:14)
...

These errors are thrown by us:

Image

The errors seem to point towards ts-only syntax.

functionWithUseGpu.ts:

{
  const myFunction = (a: number, b: number) => {
    'use gpu';
    return a + b;
  };
  console.log(myFunction);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions