ProvableHQ / sdk

A Software Development Kit (SDK) for Zero-Knowledge Transactions
https://provable.tools
GNU General Public License v3.0
592 stars 471 forks source link

[Bug] Infinite loop when building with vite #854

Open oleh-nb opened 8 months ago

oleh-nb commented 8 months ago

🐛 Bug Report

Building a project with vite build hangs because of an infinite resolution loop.

Steps to Reproduce

git clone https://github.com/oleh-nb/aleo-bug-infinite-loop.git
cd aleo-bug-infinite-loop
npm install
npm run build

Check the logs. They should look like this

Code snippet to reproduce

import { ProgramManager } from "@aleohq/sdk";
new ProgramManager();

Stack trace & error message

Click to expand ```sh vite:resolve 0.06ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +261ms vite:resolve 0.28ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.26ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms vite:resolve 0.24ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +495ms vite:resolve 0.30ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms vite:resolve 0.34ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.67ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +634ms vite:resolve 0.66ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.23ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms vite:resolve 0.17ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +645ms vite:resolve 0.25ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms vite:resolve 0.42ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.33ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +752ms vite:resolve 0.49ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.22ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms vite:resolve 0.19ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +651ms vite:resolve 0.23ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms vite:resolve 0.38ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.25ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +642ms vite:resolve 0.40ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.24ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms vite:resolve 0.22ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +647ms vite:resolve 0.34ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.18ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms vite:resolve 0.21ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +669ms vite:resolve 0.41ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.19ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms vite:resolve 0.31ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +672ms vite:resolve 0.37ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.22ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms vite:resolve 0.21ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +704ms vite:resolve 0.21ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms vite:resolve 0.37ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.18ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +653ms vite:resolve 0.46ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.22ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms vite:resolve 0.23ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +660ms vite:resolve 0.37ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.25ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms vite:resolve 0.21ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +740ms vite:resolve 0.27ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms vite:resolve 0.38ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.19ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +660ms vite:resolve 0.37ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.23ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms vite:resolve 0.24ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +677ms vite:resolve 0.61ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.22ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms vite:resolve 0.16ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +643ms vite:resolve 0.39ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.20ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms vite:resolve 0.23ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +746ms vite:resolve 0.45ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.22ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms vite:resolve 0.21ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +679ms vite:resolve 0.48ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.23ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms vite:resolve 0.13ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +692ms vite:resolve 0.52ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms vite:resolve 0.37ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.25ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +686ms vite:resolve 0.38ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.22ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms vite:resolve 0.21ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +666ms vite:resolve 0.39ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.22ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms vite:resolve 0.24ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +675ms vite:resolve 0.25ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms vite:resolve 0.35ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.24ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +662ms vite:resolve 0.53ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.21ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms vite:resolve 0.18ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +678ms vite:resolve 0.30ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms vite:resolve 0.19ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms ```

Expected Behavior

Project should be built

Your Environment

onetrickwolf commented 8 months ago

Hey I believe this was a bug in vite: https://github.com/vitejs/vite/issues/13367

They allegedly fixed it in version 5.

olehmisar commented 8 months ago

Its either not fixed or it's a different bug. I am pretty sure it's a different bug. Any idea where or why this bug occurs?

Its something related to these three files

vite:resolve 0.06ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/worker.js +261ms
  vite:resolve 0.28ms worker.js -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/sdk/dist/worker.js +0ms
  vite:resolve 0.26ms assets/aleo_wasm.wasm -> /Users/oleh-nb/Documents/Projects/aleo/bug/node_modules/@aleohq/wasm/dist/assets/aleo_wasm.wasm +0ms
onetrickwolf commented 8 months ago

Hmm I'll take a look pretty sure this is an issue with vite though seems like a similar issue and I don't see anything weird in our code. Looks like it's something to do with how vite handles nested workers which we do use.

I'll see if I can replicate in a simple example and report it to vite. I previously spent a lot of time on this and was unable to find a workaround, was waiting for them to fix it but if I find something I'll let you know. In our examples the temporary solution was to use webpack for the builds while using vite for dev but I know that's not ideal. Sorry about any inconvenience. Will try to figure something out here.