ArcherGu / fast-vite-nestjs-electron

Vite + Vue + Electron + Nestjs with esbuild, crazy fast! ⚡

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

引入 sqlite3 报错问题

jack-pearson opened this issue · comments

你好, 项目中安装 sqlit3 插件, 再 app.controller.ts 中的顶部引入 const sqlite3 = require("sqlite3").verbose(); 进行使用.

发现有报错

[main] App threw an error during load
[main] Error: package.json does not exist at /Users/liu/project/fast-vite-nestjs-electron/dist/package.json
[main] at Object.exports2.find (/Users/liu/project/fast-vite-nestjs-electron/dist/main/index.js:10682:15)
[main] at node_modules/sqlite3/lib/sqlite3-binding.js (/Users/liu/project/fast-vite-nestjs-electron/dist/main/index.js:10901:31)
[main] at __require2 (/Users/liu/project/fast-vite-nestjs-electron/dist/main/index.js:16:44)
[main] at node_modules/sqlite3/lib/sqlite3.js (/Users/liu/project/fast-vite-nestjs-electron/dist/main/index.js:10951:19)
[main] at __require2 (/Users/liu/project/fast-vite-nestjs-electron/dist/main/index.js:16:44)
[main] at src/main/app.controller.ts (/Users/liu/project/fast-vite-nestjs-electron/dist/main/index.js:11156:19)
[main] at __require2 (/Users/liu/project/fast-vite-nestjs-electron/dist/main/index.js:16:44)
[main] at src/main/app.module.ts (/Users/liu/project/fast-vite-nestjs-electron/dist/main/index.js:11351:28)
[main] at __require2 (/Users/liu/project/fast-vite-nestjs-electron/dist/main/index.js:16:44)
[main] at Object. (/Users/liu/project/fast-vite-nestjs-electron/dist/main/index.js:11371:29)
image

我看了打包过后的文件, 发现 这个包引入了package.json
image

但是我不知道如何解决, 您可以帮忙看看么?🙏🙏🙏

好了 已经找到了. 需要 external 一下 就可以了.

是的,有node binding 的都需要 external一下,这些二进制文件都是直接复制过去的。

tips: sqlit确实是和桌面客户端比较匹配的数据库,既然你已经用了这个模板,可以试下 typeorm 哦,搭配使用,效果更加。typeorm有nestjs的对应插件,你可以看下nestjs的文档。