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

imports of wasm-bindgen file reports : No loader is configured for ".wasm" files. #9890

Closed
cloudeye2 opened this issue May 8, 2023 · 5 comments · Fixed by #9909
Closed
Assignees
Labels
bug Something isn't working p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc. pkg:adapter-cloudflare

Comments

@cloudeye2
Copy link

Describe the bug

npm package using any *_bg.wasm does not import.
error looks like:

 'ERROR: No loader is configured for ".wasm" files: ...@dqbd/tiktoken/tiktoken_bg.wasm.'

vite.config.js:

export default defineConfig({
    plugins: [sveltekit(),wasm(),topLevelAwait()]
}

Reproduction URL

none

Reproduction

npm run build

Logs

> Using @sveltejs/adapter-cloudflare
✘ [ERROR] No loader is configured for ".wasm" files: node_modules/.pnpm/registry.npmmirror.com+@dqbd+tiktoken@1.0.7/node_modules/@dqbd/tiktoken/tiktoken_bg.wasm

    node_modules/.pnpm/registry.npmmirror.com+@dqbd+tiktoken@1.0.7/node_modules/@dqbd/tiktoken/tiktoken.js:1:22:
      1 │ import * as wasm from "./tiktoken_bg.wasm";~~~~~~~~~~~~~~~~~~~~

error during build:
Error: Build failed with 1 error:
node_modules/.pnpm/registry.npmmirror.com+@dqbd+tiktoken@1.0.7/node_modules/@dqbd/tiktoken/tiktoken.js:1:22: ERROR: No loader is configured for ".wasm" files: node_modules/.pnpm/registry.npmmirror.com+@dqbd+tiktoken@1.0.7/node_modules/@dqbd/tiktoken/tiktoken_bg.wasm
    at failureErrorWithLog (/Users/me/vscode-workspace/demo/node_modules/.pnpm/registry.npmmirror.com+esbuild@0.17.18/node_modules/esbuild/lib/main.js:1636:15)
    at /Users/me/vscode-workspace/demo/node_modules/.pnpm/registry.npmmirror.com+esbuild@0.17.18/node_modules/esbuild/lib/main.js:1048:25
    at /Users/me/vscode-workspace/demo/node_modules/.pnpm/registry.npmmirror.com+esbuild@0.17.18/node_modules/esbuild/lib/main.js:993:52
    at buildResponseToResult (/Users/me/vscode-workspace/demo/node_modules/.pnpm/registry.npmmirror.com+esbuild@0.17.18/node_modules/esbuild/lib/main.js:1046:7)
    at /Users/me/vscode-workspace/demo/node_modules/.pnpm/registry.npmmirror.com+esbuild@0.17.18/node_modules/esbuild/lib/main.js:1075:16
    at responseCallbacks.<computed> (/Users/me/vscode-workspace/demo/node_modules/.pnpm/registry.npmmirror.com+esbuild@0.17.18/node_modules/esbuild/lib/main.js:697:9)
    at handleIncomingPacket (/Users/me/vscode-workspace/demo/node_modules/.pnpm/registry.npmmirror.com+esbuild@0.17.18/node_modules/esbuild/lib/main.js:752:9)
    at Socket.readFromStdout (/Users/me/vscode-workspace/demo/node_modules/.pnpm/registry.npmmirror.com+esbuild@0.17.18/node_modules/esbuild/lib/main.js:673:7)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:324:12)
 ELIFECYCLE  Command failed with exit code 1.

System Info

System:
    OS: macOS 13.3.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 161.64 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 19.1.0 - /opt/homebrew/bin/node
    npm: 8.19.3 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 113.0.5672.63
    Safari: 16.4
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.0.1 
    @sveltejs/adapter-cloudflare: ^2.2.2 => 2.2.2 
    @sveltejs/adapter-vercel: ^2.4.3 => 2.4.3 
    @sveltejs/kit: ^1.5.0 => 1.16.2 
    svelte: ^3.54.0 => 3.59.0 
    vite: ^4.3.0 => 4.3.5
@cloudeye2 cloudeye2 added the bug Something isn't working label May 8, 2023
@dominikg
Copy link
Member

dominikg commented May 8, 2023

please provide the url to a minimal reproduction repo on github. Without it we won't be able to triage this issue.

@cloudeye2
Copy link
Author

please refer to:
https://github.com/cloudeye2/wasm-cloudflare-build-test

please provide the url to a minimal reproduction repo on github. Without it we won't be able to triage this issue.

@cloudeye2
Copy link
Author

FYI. changing adapter-cloudflare to apdater-vercel builds OK.

@bluwy
Copy link
Member

bluwy commented May 10, 2023

This isn't a bug in vite-plugin-svelte. The error happens during @sveltejs/adapter-cloudflare phase, which uses esbuild to bundle but it couldn't bundle wasm files. Maybe configuring esbuild with loader: { '.wasm': 'copy' } would fix it as Cloudflare supports loading WASM files at runtime.

@bluwy bluwy transferred this issue from sveltejs/vite-plugin-svelte May 10, 2023
@bluwy bluwy added p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc. pkg:adapter-cloudflare labels May 10, 2023
@cloudeye2
Copy link
Author

truly it looks a problem of @sveltejs/adapter-cloudflare,
but seems cannot configure esbuild behavior in adapter-cloudflare like mentioned: loader:{'.wasm','copy'}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc. pkg:adapter-cloudflare
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants