ArcherGu / fast-vite-nestjs-electron

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

添加了TypeOrm后,服务注入报错

veryws opened this issue · comments

微信截图_20220718193107

服务层添加“ constructor(@InjectRepository(CWell) private readonly repository:Repository ){}”就报错,移出就正常,提示让安装“pg-native”,但pg-native的安装,需要更多的工具,确认不支持TypeOrm嘛?

image

这个是支持的,只不过这些原生的node库需要在 vite.config.ts -> plugins -> VitePluginElectronBuilder 中的 external 字段中添加进去,这样在构建的时候不会将他们也打包进去。

下面是我一个基于此模板写的项目中用到的一些库,大部分的原生库其实都是支持 electron/node 双环境的:

external: [
     'modbus-serial',
     '@serialport',
     '@nestjs',
     'typeorm',
     'sqlite3',
]

你在写 nestjs 后端或者其他 node 后端的时候,其实也是这样的,它们仅仅构建你写的代码,而不会将相关的引用也包含进去,这个和前端是不一样的。