Skip to content

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

Description

@kerryChen95

问题复现步骤

eggjs新建 TS 项目。 egg@2.33.1, swagger-egg@1.7.0

正常写 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();

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions