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

WebGPURenderer: Top-level await is not available in vite. #26626

Closed
linbingquan opened this issue Aug 22, 2023 · 3 comments
Closed

WebGPURenderer: Top-level await is not available in vite. #26626

linbingquan opened this issue Aug 22, 2023 · 3 comments

Comments

@linbingquan
Copy link
Contributor

Description

As the title.

✘ [ERROR] Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)

    node_modules/.pnpm/three@0.155.0/node_modules/three/examples/jsm/renderers/webgpu/WebGPUBackend.js:24:18:
      24 │   _staticAdapter = await navigator.gpu.requestAdapter();
         ╵                    ~~~~~

Reproduction steps

  1. pnpm create vite threejs-template --template vanilla-ts

  2. cd threejs-template

  3. pnpm install

  4. pnpm install -D three

  5. replace main.ts source code with:

import WebGPURenderer from "three/examples/jsm/renderers/webgpu/WebGPURenderer.js";

new WebGPURenderer();
  1. pnpm dev

the terminal will show the error info

Code

node --version
v18.17.1

Live example

None

Screenshots

No response

Version

r155

Device

Desktop

Browser

No response

OS

Windows

@CodyJasonBennett
Copy link
Contributor

I just ran into this with my four library for the same reason. This comes from Vite's optimizeDeps, they're strangely very loose -- notably looser than WebGPU/WebGL 2 supported browsers.

You can use https://github.com/Menci/vite-plugin-top-level-await or tweak the target with:

// vite.config.js
optimizeDeps: {
  esbuildOptions: {
    target: 'esnext'
  }
},
build: {
  target: 'esnext'
}

It's a bit unfortunate Vite/ESBuild/browserslist is pedantic about this since ESM spec guarantees the availability of top-level await since early 2021. I'm not aware of a workaround for libraries at the moment.

@Mugen87 Mugen87 added Nodes and removed Nodes labels Aug 22, 2023
@Mugen87
Copy link
Collaborator

Mugen87 commented Aug 22, 2023

three.js requires a static (WebGPU) adapter for its API so I fear it will be hard to fix this on engine level. Let's hope the tooling will improve support for top-level await soon.

@coderextreme
Copy link

I just ran into this with my four library for the same reason. This comes from Vite's optimizeDeps, they're strangely very loose -- notably looser than WebGPU/WebGL 2 supported browsers.

You can use https://github.com/Menci/vite-plugin-top-level-await or tweak the target with:

// vite.config.js
optimizeDeps: {
  esbuildOptions: {
    target: 'esnext'
  }
},
build: {
  target: 'esnext'
}

It's a bit unfortunate Vite/ESBuild/browserslist is pedantic about this since ESM spec guarantees the availability of top-level await since early 2021. I'm not aware of a workaround for libraries at the moment.

Is this good if I'm not doing a build, just using THREE?

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

4 participants