tsrpc icon indicating copy to clipboard operation
tsrpc copied to clipboard

关于该框架使用ESM规范问题

Open Mr-Hy opened this issue 5 months ago • 1 comments

如果遇到项目中严格遵守ESM规范的情况,package.json的"type": "module",tsconfig中的配置也全是ESNext,这时候用cli的build就会报错,因为框架是CommonJS规范对tsrpc.config.ts文件进行引用的,如果在严格的ESM模式下,就会报错:

错误 Must use import to load ES Module: D:\hy\object\server\tsrpc.config.ts require() of ES modules is not supported. require() of D:\hy\object\server\tsrpc.config.ts from D:\hy\object\server\node_modules\tsrpc-cli\bin.js is an ES module file as it is a .ts file whose nearest parent package.json contains "type": "module" which defines all .ts files in that package scope as ES modules. Instead change the requiring code to use import(), or remove "type": "module" from D:\hy\object\server\package.json.

这种情况有办法解决吗?

Mr-Hy avatar Sep 23 '25 02:09 Mr-Hy

受限于一些机制原因,目前 3.x 后端支持 ESM 需要一些时间。 前端客户端支持 ESM。

即将推出的 4.x 会彻底解决这个问题。

k8w avatar Nov 17 '25 12:11 k8w