TSC 在 github-action 期间构建错误,但在本地编译正常

Jim*_*ahy 6 typescript github-actions

通过actDocker 在本地测试 github-actions 时,我在 github-action 工作流程中遇到了各种 TS 错误(TS2345、TS18046、TS2339 等...)。在本地开发期间不会观察到这些错误,并且tsc -p tsconfig.build.json在本地计算机上运行会导致编译成功。

github-action 正在运行ubuntu-latest,我已确认运行器已配置为使用与本地版本相同的节点、npm、yarn 和 tsc 版本。

  • 节点-v18.13.0
  • npm -v8.19.3
  • 纱线-1.22.19
  • tsc-v4.9.4

此外,我已经确认 TSC 在 github-action 期间使用的配置与我的本地配置相同(来自 的输出tsc --showConfig,比较本地和 github-action 的差异)。使用 github-action 中的相同 docker 容器,我可以访问终端并运行相同的命令,而不会看到错误。

鉴于节点、npm、yarn 和 tsc 版本在我的本地和 github-action 中是相同的,什么可能导致这种不同的行为?

tsconfig.json

{
  "compilerOptions": {
    "rootDir": "./src",
    "module": "commonjs",
    "declaration": false,
    "noImplicitAny": false,
    "skipLibCheck": true,
    "removeComments": true,
    "noLib": false,
    "allowSyntheticDefaultImports": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "target": "ES2021",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "src",
    "incremental": true,
    "strictNullChecks": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules", "**/*.spec.ts"],
  "paths": {
    "@module": ["src/module"]
  }
}

Run Code Online (Sandbox Code Playgroud)

Bre*_*sen 1

由于您的问题很久以前就被问过,我刚刚在这里发布了一个非常类似的问题,也许这也会对您有所帮助。基本上,不在工作流程中安装所需的包可能会导致其他 TS 错误。只需添加uses: npm install之前就run: tsc -p tsconfig.json可以完成我的工作。