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

Cloudflare adapter doesn't support WASM, despite natively supporting WASM modules #8541

Closed
1 task done
adrianlyjak opened this issue Sep 13, 2023 · 0 comments · Fixed by #8542
Closed
1 task done
Labels
- P2: nice to have Not breaking anything but nice to have (priority)

Comments

@adrianlyjak
Copy link
Contributor

adrianlyjak commented Sep 13, 2023

Astro Info

Astro                    v3.0.12
Node                     v20.6.1
System                   macOS (arm64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/cloudflare
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

When attempting to import and bundle a wasm module, the cloudflare adapter throws errors from vite and esbuild, despite wasm module import being possible in native cloudflare worker imports.

When attempting to import a wasm file, you'll see the following error during an astro dev server:

Failed to parse source for import analysis because the content contains invalid JS syntax. You may need to install appropriate plugins to handle the .wasm file format, or if it's an asset, add "**/*.wasm" to `assetsInclude` in your configuration.

This appears to be coming from the initial vite build. Adding vite plugin for wasm, such as this, and marking the import as a .wasm?module is promising: it gets the astro dev server running. However when running astro build, further errors are thrown when esbuild doesn't know what to do with the .wasm import when bundling.

$ npx astro build
# ...
✘ [ERROR] Could not resolve "./../../_astro/add.f61fd62f.wasm"

    dist/$server_build/chunks/pages/index_0ed3720d.mjs:1:17:
      1 │ import init from './../../_astro/add.f61fd62f.wasm';

What's the expected result?

It seems like wasm module style imports should be relatively straight forward to support since they are native to cloudflare. From what I've tried, its also the only way in cloudflare to import a wasm file. (loading a fetched file from binary throws errors in the cloudflare runtime).

Additionally, adding support for wasm in cloudflare should also help add sharp support to the cloudflare adapter in the future once there's a web assembly build of sharp

Link to Minimal Reproducible Example

https://github.com/adrianlyjak/astro/tree/1d780c08b44184a2306a8ba181160e4928a88cd6/packages/integrations/cloudflare/test/fixtures/wasm

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Sep 13, 2023
adrianlyjak added a commit to adrianlyjak/astro that referenced this issue Sep 13, 2023
adrianlyjak added a commit to adrianlyjak/astro that referenced this issue Sep 13, 2023
adrianlyjak added a commit to adrianlyjak/astro that referenced this issue Sep 13, 2023
adrianlyjak added a commit to adrianlyjak/astro that referenced this issue Sep 13, 2023
adrianlyjak added a commit to adrianlyjak/astro that referenced this issue Sep 13, 2023
adrianlyjak added a commit to adrianlyjak/astro that referenced this issue Sep 13, 2023
adrianlyjak added a commit to adrianlyjak/astro that referenced this issue Sep 13, 2023
adrianlyjak added a commit to adrianlyjak/astro that referenced this issue Sep 13, 2023
adrianlyjak added a commit to adrianlyjak/astro that referenced this issue Sep 13, 2023
adrianlyjak added a commit to adrianlyjak/astro that referenced this issue Sep 14, 2023
@lilnasy lilnasy added - P2: nice to have Not breaking anything but nice to have (priority) pkg: cloudflare and removed needs triage Issue needs to be triaged labels Sep 14, 2023
adrianlyjak added a commit to adrianlyjak/astro that referenced this issue Sep 15, 2023
adrianlyjak added a commit to adrianlyjak/astro that referenced this issue Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants