Dexie.js icon indicating copy to clipboard operation
Dexie.js copied to clipboard

ReferenceError: self is not defined

Open aspeculat0r opened this issue 3 years ago • 6 comments
trafficstars

I am using dexie-export-import in svelte-kit. When I have a statement import "dexie-export-import" I get a reference error. image

image

aspeculat0r avatar Jul 20 '22 01:07 aspeculat0r

dexie-export-import is a client-side library so you'd need to avoid it being executed on the server.

dfahlander avatar Jul 22 '22 09:07 dfahlander

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 avatar Apr 28 '23 14:04 DjakaTechnology

@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.

dfahlander avatar Apr 28 '23 15:04 dfahlander

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.

fev4 avatar Jun 18 '23 02:06 fev4