Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TSC build errors during github-action but compiles fine locally

Using act to locally test github-actions via Docker, I am getting a variety of TS errors (TS2345, TS18046, TS2339, etc...) during my github-action workflow. These errors are not observed during local development and running tsc -p tsconfig.build.json on my local machine results in a successful compilation.

The github-action runs on ubuntu-latest and I have confirmed that the runner is configured to use the same versions of node, npm, yarn and tsc as my local.

  • Node - v18.13.0
  • npm - v8.19.3
  • yarn - 1.22.19
  • tsc - v4.9.4

Furthermore, I have confirmed that the config TSC uses during the github-action is identical to my local config (output from tsc --showConfig, compared diff from local and github-action). Using the same docker container from the github-action, I can access the terminal and run the same commands without seeing the errors.

Given that the node, npm, yarn and tsc versions are the same across my local and github-action, what could possible cause this different behavior?

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"]
  }
}

like image 206
Jimmy Leahy Avatar asked Apr 08 '26 01:04

Jimmy Leahy


2 Answers

I had a similar issue and it was caused by not having all the packages listed in package.json.

I'm still not sure why it built successfully locally (perhaps I had leftover files in node_modules?) but I traced the error messages to the specific lines and found that it was due to a particular import that was missing. Added it to package.json and the errors went away.

like image 165
Dov Rosenberg Avatar answered Apr 11 '26 01:04

Dov Rosenberg


Since your question was asked quite some time ago, I just posted a very similar question here, perhaps this'll help you out as well. Basically, not installing the required packages in your workflow can cause other TS errors. Simply adding uses: npm install before run: tsc -p tsconfig.json did the job for me.

like image 37
Brent Meeusen Avatar answered Apr 11 '26 00:04

Brent Meeusen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!