I have a working project in .NET 6 that calls the following JS code:
export function synchronizeFileWithIndexedDb(filename) {
return new Promise((res, rej) => {
const db = window.indexedDB.open('SqliteStorage', 1);
db.onupgradeneeded = () => {
db.result.createObjectStore('Files', { keypath: 'id' });
};
db.onsuccess = () => {
const req = db.result.transaction('Files', 'readonly').objectStore('Files').get('file');
req.onsuccess = () => {
Module.FS_createDataFile('/', filename, req.result, true, true, true);
res();
};
};
});
}
And behind the scenes in OnInitializedAsync:
if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("browser")))
{
// create SQLite database file in browser
var module = await _js.InvokeAsync<IJSObjectReference>("import", "./dbstorage.js");
await module.InvokeVoidAsync("synchronizeFileWithIndexedDb", SqliteDbFilename);
}
This works perfectly in .NET 6, which is unfortunately now EOL.
Simply upgrading it to .NET 8 causes "Module" (see line 11) to no longer be defined. I ran into the same problem using a brand new .NET 9 project as well. If it's .NET 6 it works, .NET 8 or higher it breaks.
Is this a known issue? I'm afraid of upgrading anything with JS Interop now