TypeScript and Docker - compilation error
# help
h
TypeScript and Docker - compilation error
Hey, i am trying to compile Cypress project, with spec files written in TypeScript, inside Docker (i use officla image
included/9.1.1
from https://github.com/cypress-io/cypress-docker-images/tree/master/included/9.1.1) and i receive error: > error TS2688: Cannot find type definition file for 'cypress'. I have installed TypeScript with
npm install -g typescript
. The command i use to compile project is:
Copy code
sh
tsc --project cypress/tsconfig.cypress.json
tsconfig.cypress.json
file:
Copy code
json
{
    "compilerOptions": {
      "target": "es2020",
      "lib": ["es5", "dom"],
      "types": ["cypress"],
      "allowJs": true,
    },
    "include": ["./integration/*.spec.ts"]
  }
The mere Cypress has worked until i have been trying to add TypeScript. From what i saw there are Cypress types inside
/usr/local/lib/node_modules/cypress/types
folder and i even tried to put it inside
typeRoots
prop, but then i receive errors of lacking definition files for
npm
and
yarn
.
I think i fixed the issue. I investigated Cypress example repo for TypeScript integration (https://github.com/cypress-io/cypress-and-jest-typescript-example) and realized that they also install types for
chai
and
mocha
and that the Cypress types are really included inside
/usr/local/lib/node_modules/cypress/types
folder (mind
"/types"
instead of
"/@types"
- don't know why they named it without
"@"
though), so i don't have to install Cypress package separately, but just point to already existing types. I also had to add
"ES2015"
lib types and modify
"include"
to take all .ts files inside Cypress (nested) folders - except the
/src
, which is provided by Docker volume not to mess with app's source code - instead of just including
./integration/*.spec.ts
files. I now just install these:
Copy code
sh
npm install -g typescript
npm install @types/mocha @types/chai
And i have such `tsconfig.cypress.json`:
Copy code
json
{
    "compilerOptions": {
      "target": "es2020",
      "module": "commonjs",
      "lib": ["es5", "ES2015", "dom"],
      "typeRoots": [
        // official Cypress Docker container keeps types there
        "/usr/local/lib/node_modules/cypress/types",
      ],
      "types": ["cypress"],
      "allowJs": true,
      "resolveJsonModule": true
    },
    "include": ["./**/*.ts"],
    "exclude": ["./fixtures/src"]
}
2 Views