I'm building a desktop app using tauri with Next.js and when I try to create a new window, on first load it fails, but if I comment and uncomment the code it works perfectly.
As it's on the first load, I can't even compile the build.
Here's the portion of the code to open a new window:
const openWindow = async (e) => {
const table = JSON.stringify({
host: active.host,
port: active.port,
user: active.user,
password: active.password,
database: e,
});
try {
await new WebviewWindow("test", {
url: "/database?data=" + table,
});
} catch (e) {
console.log("error", e);
}
};
And here's where I invoke que function to open the window:
{loading === false
? databases.map((database) => {
return (
<Tr>
<Td>
<Button
onClick={() => openWindow(database.dbname)}
variant={"link"}
>
{database.dbname}
</Button>
</Td>
<Td isNumeric>{database.tablecnt}</Td>
<Td isNumeric>{database.indexcnt}</Td>
<Td isNumeric>{database.viewcnt}</Td>
<Td isNumeric>{database.proccnt}</Td>
</Tr>
);
})
: null}
Here's the error I get:
error - ReferenceError: window is not defined
at file:///D:/proyectos/sql-defrag/node_modules/@tauri-apps/api/chunk-QSWLDHGO.js:1:9678
at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
at async importModuleDynamicallyWrapper (node:internal/vm/module:437:15) {
page: '/'
}
If anyone has any clue I'd appreciate some help.