swagger-egg icon indicating copy to clipboard operation
swagger-egg copied to clipboard

TS应用中默认的 `yarn start` 命令启动报错

Open kerryChen95 opened this issue 2 years ago • 0 comments

问题复现步骤

eggjs新建 TS 项目。 [email protected], [email protected]

正常写 app/schema/definitions.ts

yarn run tsc ,再 yarn start

问题表现

[egg-scripts] File '<egg-app>/app/schema/definitions.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
[egg-scripts]   The file is in the program because:
[egg-scripts]     Root file specified for compilation

奇怪为什么 app/schema/definitions.js 会成为 root file。

在 egg-scripts 中断点拿到的此异常的信息 error TS6504: File '*.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?

尝试解决未果

eggjs为TS应用生成的 tsconfig.json 中为 compilerOptions.allowJs: false ,不确定eggjs是否对此强依赖。如果改成 true,那么在 yarn run tsc 时会报错,或许是强依赖,没继续深入研究。

error TS2347: Untyped function calls may not accept type arguments.
error TS2339: Property 'mongoose' does not exist on type 'MockApplication'.
const invalidAccountAppId = (new app.mongoose.Types.ObjectId()).toString();

kerryChen95 avatar Apr 13 '22 09:04 kerryChen95