[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?
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();
问题复现步骤
eggjs新建 TS 项目。
egg@2.33.1
,swagger-egg@1.7.0
正常写
app/schema/definitions.ts
。先
yarn run tsc
,再yarn start
。问题表现
奇怪为什么
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
时会报错,或许是强依赖,没继续深入研究。