tiddly-gittly / TidGi-Desktop

TidGi is an privacy-in-mind, automated, auto-git-backup, freely-deployed knowledge management Desktop note app, based on Tiddlywiki, with REST API for web-clipping and Anki connect. 「 太记 」是一个基于「 太微 TiddlyWiki 」的知识管理桌面应用,能保护隐私内容、高级自动化、自动Git云备份、部署为博客,且可通过RESTAPI与Anki等应用连接。(迭代开发中欢迎试用,开发进度见下方链接)(Under active development, see website below for details)
https://tidgi.fun
Mozilla Public License 2.0
1.74k stars 111 forks source link

bug: Electron-Forge webpack error: self is not defined , after adding npm package with esm module #403

Closed linonetwo closed 1 year ago

linonetwo commented 1 year ago

Environment

TidGi 0.8.0-prerelease9 Electron 24.3.1 darwin 22.4.0 Locale: zh-CN

Description:

Steps to Reproduce:

After enable sqlite-vss

Additional Context

ReferenceError: self is not defined
    at $:/boot/bootprefix.js:40749:36
    at $:/boot/bootprefix.js:40763:13
    at Object.<anonymous> ($:/boot/bootprefix.js:41069:12)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1296:10)
    at Module.load (node:internal/modules/cjs/loader:1096:32)
    at Module._load (node:internal/modules/cjs/loader:937:12)
    at f._load (node:electron/js2c/asar_bundle:2:13330)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at MessagePort.<anonymous> (node:internal/main/worker_thread:161:24)


/******/    /* webpack/runtime/importScripts chunk loading */
/******/    (() => {
/******/        __webpack_require__.b = self.location + ""; // :40749:36
/******/        
/******/        // object to store loaded chunks
/******/        // "1" means "already loaded"
/******/        var installedChunks = {
/******/            "wikiWorker": 1
/******/        };
})();

/******/ })() // :41069:12
;
//# sourceMappingURL=wikiWorker.index.worker.js.map
linonetwo commented 1 year ago

原因是 sqlite-vss 里用到 fileURLToPath(new URL(".", import.meta.url)), 会被转换成对 webpack/runtime/importScripts 的调用,而 webpack/runtime/importScripts 有bug,用到的 self 是 undefined。

linonetwo commented 1 year ago

https://github.com/tiddly-gittly/TidGi-Desktop/commit/426728fc610388f3f257ed53ccfad1a12f339f24 后,正常的报错信息变为

Unhandled Error
ReferenceError: self is not defined
    at /Users/linonetwo/Desktop/repo/TiddlyGit-Desktop/.webpack/main/wikiWorker.index.worker.js:37794:36
    at /Users/linonetwo/Desktop/repo/TiddlyGit-Desktop/.webpack/main/wikiWorker.index.worker.js:37808:13
    at Object.<anonymous> (/Users/linonetwo/Desktop/repo/TiddlyGit-Desktop/.webpack/main/wikiWorker.index.worker.js:38114:12)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1296:10)
    at Module.load (node:internal/modules/cjs/loader:1096:32)
    at Module._load (node:internal/modules/cjs/loader:937:12)
    at f._load (node:electron/js2c/asar_bundle:2:13330)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at MessagePort.<anonymous> (node:internal/main/worker_thread:161:24)