Issue
Hello i have an issue with one of my Jenkins pipelines when trying to build a TypeScript application.
The pipeline checkouts the TypeScript project and runs:
yarn install
yarn build
However during the build i errors and the pipeline fails with the error:
│ TS2571: Object is of type 'unknown'.
I tried to recreate this error on an AWS EC2 instance which uses the same AMI image as my Jenkins EC2. I made sure to use the same version of node (v12.22.3) that my Jenkins service is using. However after running yarn install + build, I don't get this error. And the build succeeds.
I can see the error in Jenkins logs is referring to an 'error' variable:
} catch (error) {
expect(error.name).toEqual('Error');
}
And after googling this error it seems like the solution could be to update the code to include a type on the error object (due to a TypeScript update), however this isn't my code, i'm not a typescript dev, and i know the code builds on my VM using the same version as node.js. So surely i can get it to work on Jenkins?
Does any one have any tips to help debug this? Thanks
Solution
I'm betting you have different versions of Typescript installed. You may have different versions of typescript installed.
In Typescript 3.5.1 a caught error was of type any
. See playground
In Typescript 4.6.2 a caught error was of type unknown
. See playground
Looks like was in Typescipt 4.4 (see this release note).
Somewhere in between those two versions the type was changed. And it looks like your CI server is running a more recent version than your local environment is.
And if your machine and your CI server are depending on a globally installed typescript the versions could be very different. I would recommend you update your local typescript to match what you have on CI.
Answered By - Alex Wayne
Answer Checked By - Robin (JavaFixing Admin)