Open
Description
Command
test
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
Current Angular (19.x), but not using Application Builder for Karma
Description
Unit tests using esbuild + Vite fail when reloading using Sqlite wasm.
- App is configured to use esbuild + Vite for unit testing with Jasmine + Karma.
- App imports Sqlite one way in production, but in tests, it is loaded via wasm in order to test Sql code.
- Start the test run with
npm test
. - It will build the app and run the tests successfully once.
- You will see a log in the output that says:
wasm size: 739,512 bytes
.
- You will see a log in the output that says:
- Open
sqlite-db.service.spec.ts
and save. - This should rebuild the tests and you will see a failure:
failed to asynchronously prepare wasm: CompileError: WebAssembly.instantiate(): section (code 1, "Type") extends past end of the module (length 9396207, remaining bytes 828774) @+8
- You will see a log in the output that says
wasm size: 828,787 bytes
.
- You will see a log in the output that says
- The size of the actual file being read from disk matches the first logged size, and it does not change when you save.
- The actual file can be found at
dist/test-out/**/sql-wasm-debug.wasm
, and you can see its size does not change. It always matches the original file size of 739,512 bytes.
What could be going on that would cause this wasm to load differently on initial load of the tests vs a rebuild after save?
Minimal Reproduction
git clone https://github.com/ekrapfl/sqlite-esbuild.git
cd sqlite-esbuild
- Repro is in default/main branch, so shouldn't need to change branches.
npm ci
npm test
- It will build the app and run the tests with the following output:
Application bundle generation complete. [1.580 seconds]
Watch mode enabled. Watching for file changes...
29 04 2025 21:36:17.505:WARN [karma]: No captured browser, open http://localhost:9876/
29 04 2025 21:36:17.511:INFO [karma-server]: Karma v6.4.4 server started at http://localhost:9876/
29 04 2025 21:36:17.511:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited
29 04 2025 21:36:17.514:INFO [launcher]: Starting browser ChromeHeadless
29 04 2025 21:36:18.764:INFO [Chrome Headless 136.0.0.0 (Mac OS 10.15.7)]: Connected on socket cHfvDDYgr26RL9A3AAAB with id 67563794
Chrome Headless 136.0.0.0 (Mac OS 10.15.7): Executed 0 of 1 SUCCESS (0 secs
WARN: 'wasm size: 739,512 bytes'
Chrome Headless 136.0.0.0 (Mac OS 10.15.7): Executed 0 of 1 SUCCESS (0 secs
Chrome Headless 136.0.0.0 (Mac OS 10.15.7): Executed 1 of 1 SUCCESS (0 secs
Chrome Headless 136.0.0.0 (Mac OS 10.15.7): Executed 1 of 1 SUCCESS (0.04 secs / 0.039 secs)
TOTAL: 1 SUCCESS
- Open
sqlite-db.service.spec.ts
and save. - This should rebuild the tests and you will see the following failure:
Application bundle generation complete. [0.220 seconds]
Chrome Headless 136.0.0.0 (Mac OS 10.15.7): Executed 0 of 1 SUCCESS (0 secs
WARN: 'wasm size: 828,787 bytes'
Chrome Headless 136.0.0.0 (Mac OS 10.15.7): Executed 0 of 1 SUCCESS (0 secs
ERROR: 'failed to asynchronously prepare wasm: CompileError: WebAssembly.instantiate(): section (code 1, "Type") extends past end of the module (length 9396207, remaining bytes 828774) @+8'
Chrome Headless 136.0.0.0 (Mac OS 10.15.7): Executed 0 of 1 SUCCESS (0 secs
ERROR: 'Aborted(CompileError: WebAssembly.instantiate(): section (code 1, "Type") extends past end of the module (length 9396207, remaining bytes 828774) @+8)'
Chrome Headless 136.0.0.0 (Mac OS 10.15.7): Executed 0 of 1 SUCCESS (0 secs
Chrome Headless 136.0.0.0 (Mac OS 10.15.7) SqliteDBService Sets and gets data FAILED
Error: CompileError: WebAssembly.instantiate(): section (code 1, "Type") extends past end of the module (length 9396207, remaining bytes 828774) @+8
at Object.Module.onAbort (node_modules/sql.js/dist/sql-wasm-debug.js:36:14)
at abort (node_modules/sql.js/dist/sql-wasm-debug.js:1901:23)
at node_modules/sql.js/dist/sql-wasm-debug.js:1979:9
at Generator.throw (<anonymous>)
at rejected (chunk-GGUFBIL7.js:67:29)
at _ZoneDelegate.invoke (node_modules/zone.js/fesm2015/zone.js:369:28)
at _ProxyZoneSpec.onInvoke (node_modules/zone.js/fesm2015/zone-testing.js:2020:33)
at _ZoneDelegate.invoke (node_modules/zone.js/fesm2015/zone.js:368:34)
at ZoneImpl.run (node_modules/zone.js/fesm2015/zone.js:111:43)
at node_modules/zone.js/fesm2015/zone.js:2538:40
Chrome Headless 136.0.0.0 (Mac OS 10.15.7): Executed 1 of 1 (1 FAILED) (0 s
ERROR: RuntimeError: Aborted(CompileError: WebAssembly.instantiate(): section (code 1, "Type") extends past end of the module (length 9396207, remaining bytes 828774) @+8)
RuntimeError: Aborted(CompileError: WebAssembly.instantiate(): section (code 1, "Type") extends past end of the module (length 9396207, remaining bytes 828774) @+8)
at abort (http://localhost:9876/base/node_modules/sql.js/dist/sql-wasm-debug.js:1922:15)
at http://localhost:9876/base/node_modules/sql.js/dist/sql-wasm-debug.js:1979:9
at Generator.throw (<anonymous>)
at rejected (http://localhost:9876/base/chunk-GGUFBIL7.js:67:29)
at _ZoneDelegate.invoke (http://localhost:9876/base/node_modules/zone.js/fesm2015/zone.js:369:28)
at _ProxyZoneSpec.onInvoke (http://localhost:9876/base/node_modules/zone.js/fesm2015/zone-testing.js:2020:33)
at _ZoneDelegate.invoke (http://localhost:9876/base/node_modules/zone.js/fesm2015/zone.js:368:34)
at ZoneImpl.run (http://localhost:9876/base/node_modules/zone.js/fesm2015/zone.js:111:43)
at http://localhost:9876/base/node_modules/zone.js/fesm2015/zone.js:2538:40
at _ZoneDelegate.invokeTask (http://localhost:9876/base/node_modules/zone.js/fesm2015/zone.js:402:33)
Chrome Headless 136.0.0.0 (Mac OS 10.15.7): Executed 1 of 1 (1 FAILED) (0 s
Chrome Headless 136.0.0.0 (Mac OS 10.15.7): Executed 1 of 1 (1 FAILED) (0.013 secs / 0.009 secs)
TOTAL: 1 FAILED, 0 SUCCESS
Exception or Error
Your Environment
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 19.2.9
Node: 22.14.0
Package Manager: npm 10.9.2
OS: darwin arm64
Angular: 19.2.8
... common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1902.9
@angular-devkit/build-angular 19.2.9
@angular-devkit/core 19.2.9
@angular-devkit/schematics 19.2.9
@angular/cli 19.2.9
@schematics/angular 19.2.9
rxjs 7.8.2
typescript 5.7.3
zone.js 0.15.0
Anything else relevant?
NOTE: I have also tried using sqlite-wasm instead of sql.js with essentially the exact same results.
I marked this as regression because it works in Angular v19.x if I use Webpack instead of Application Builder. I did not include an example of this, as it requires a custom webpack plugin and is a bit painful to get setup. If someone would like that working example, I would be happy to provide it, though.
Any help would be appreciated!