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

update for Vite #4

Merged
merged 12 commits into from
Dec 22, 2024
Merged

update for Vite #4

merged 12 commits into from
Dec 22, 2024

Conversation

AlexErrant
Copy link
Contributor

Hi, thanks for a great library. This PR updates the Readme with instructions for Vite and adds Vite to the test suite.


Without @surma/rollup-plugin-off-main-thread, the vite build command fails with

❯ npx vite build
vite v5.1.4 building for production...
transforming (1) index.html
<--- Last few GCs --->

[517549:0x572c270]    75048 ms: Mark-sweep 4041.1 (4138.2) -> 4030.7 (4141.4) MB, 1570.5 / 0.0 ms  (average mu = 0.195, current mu = 0.041) task; scavenge might not succeed
[517549:0x572c270]    77747 ms: Mark-sweep 4045.6 (4142.2) -> 4034.5 (4145.2) MB, 2632.7 / 0.0 ms  (average mu = 0.094, current mu = 0.025) task; scavenge might not succeed


<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
 1: 0xb7a940 node::Abort() [node]
 2: 0xa8e823  [node]
 3: 0xd5c940 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
 4: 0xd5cce7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
 5: 0xf3a3e5  [node]
 6: 0xf4c8cd v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
 7: 0xfbb924 v8::internal::ScavengeJob::Task::RunInternal() [node]
 8: 0xe2c07b non-virtual thunk to v8::internal::CancelableTask::Run() [node]
 9: 0xbe6884  [node]
10: 0xbe9cee node::PerIsolatePlatformData::FlushForegroundTasksInternal() [node]
11: 0x165eb16  [node]
12: 0x1671054  [node]
13: 0x165f47e uv_run [node]
14: 0xabda6d node::SpinEventLoop(node::Environment*) [node]
15: 0xbc1164 node::NodeMainInstance::Run() [node]
16: 0xb35bc8 node::LoadSnapshotDataAndRun(node::SnapshotData const**, node::InitializationResult const*) [node]
17: 0xb3976f node::Start(int, char**) [node]
18: 0x7f46b3fb0083 __libc_start_main [/lib/x86_64-linux-gnu/libc.so.6]
19: 0xabbdee _start [node]
Aborted

However, with @surma/rollup-plugin-off-main-thread, the dev server npx vite dev causes the page to try to load http://localhost:5173/pkg/snippets/wasm-bindgen-rayon-3e04391371ad0a8e/src/undefined which obviously doesn't exist and results in Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec. Possibly related.

Therefore, we conditionally use @surma/rollup-plugin-off-main-thread based on Vite's "mode".

@AlexErrant
Copy link
Contributor Author

AlexErrant commented Feb 28, 2024

On a separate but related PR, I noticed that vite build fails with the same "JavaScript heap out of memory" error when using wasm-bindgen-rayon in a separate webworker (as was mandatory in <=v1.1.3) even when using @surma/rollup-plugin-off-main-thread. I had to move the code out of the web worker to get vite build to work.

Hypothetically, if I wanted to use a separate web worker, would you know the solution to this? Don't waste too much time if you don't know - I really don't mind not having to spin up another worker. Just asking for the sake of completeness :)


Edit: Updating Vite to 5.1.6 (released a few weeks after this comment) or higher fixes this issue.

@AlexErrant
Copy link
Contributor Author

Updating Vite to 5.1.6+ removes the need for @surma/rollup-plugin-off-main-thread. This PR now simply adds a test, which may be useful to guard against regressions.

@9SMTM6
Copy link
Contributor

9SMTM6 commented Oct 4, 2024

@RReverser since this only adds a test case at this point, it should be unproblematic to rebase and merge.

test/vite.config.mjs Outdated Show resolved Hide resolved
@RReverser RReverser merged commit cd6eabe into RReverser:main Dec 22, 2024
1 check failed
@RReverser
Copy link
Owner

Thanks!

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

Successfully merging this pull request may close these issues.

3 participants