Open aspeculat0r opened 2 years ago
dexie-export-import is a client-side library so you'd need to avoid it being executed on the server.
I also got this error when building for client side tauri in NextJs
ReferenceError: self is not defined
at C:\Projects\raita-desktop\raita-web\front-end\node_modules\dexie-export-import\dist\dexie-export-import.js:2022:54
at C:\Projects\raita-desktop\raita-web\front-end\node_modules\dexie-export-import\dist\dexie-export-import.js:20:68
at Object.<anonymous> (C:\Projects\raita-desktop\raita-web\front-end\node_modules\dexie-export-import\dist\dexie-export-import.js:23:3)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.7150 (C:\Projects\raita-desktop\raita-web\front-end\.next\server\pages\app\components\settings\database_export_import.js:18:18) {
type: 'ReferenceError'
}
@DjakaTechnology NextJS will compile all your components under pages for both frontend and backend (node-based). The dexie-export-import addon probably fails when required from the backend because it was written for frontend.
We used to have similar problem with dexie-cloud-addon and at that time, we encouraged users to use dymanic import of components that depended on it. Now, this was fixed in dexie-cloud-addon but may still be an issue in dexie-export-import. To work around, use dynamic import to import any component that depend the failing module. Dynamic import in nextjs makes the code only execute client side.
If anyone else finds themselves with this problem, give this a try:
onMount(async () => {
await import('dexie-export-import');
});
It's working on my end.
If anyone else finds themselves with this problem, give this a try:
onMount(async () => { await import('dexie-export-import'); });
It's working on my end.
where onMount
is coming from?
the following code worked for me in NextJS
import { db } from './connection';
const exportDB = async () => {
if (typeof window !== 'undefined') {
await import('dexie-export-import');
}
const blob = await db.export();
console.log('blob===>', blob);
};
export { exportDB };
I am using dexie-export-import in svelte-kit. When I have a statement import "dexie-export-import" I get a reference error.