Unknown file extension ".ts" cypress.config.ts on CI

Viewed 922

When I run npm run cypress:run in my GitLab CI env I get the error:

Your configFile is invalid: //WebApp/cypress.config.ts It threw an error when required, check the stack trace below: TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for //WebApp/cypress.config.ts

test:cypress:
  image:
    name: cypress/included:10.3.1-typescript
    entrypoint: ['']
  stage: test
  script:
    - yarn install --frozen-lockfile
    - cd WebApp
    - npm run cypress:run
  rules:
    - *branch

If I run npm run cypress:run from the WebApp folder (where cypress.config.ts is in the root) locally I have no issue. Also no issues when I do an npx cypress:run

However, if I run npx cypress run --config-file WebApp/cypress.config.ts from the parent folder locally I do get the error:

Unknown file extension ".ts"

Any ideas why locally Cypress is working but on the CI the config file is incorrect?

4 Answers

It looks like it's about the version. This might be hepful GitHub

I have tried all different ways suggested in the GitHub issue that user18025789 linked, but nothing helped. Then I tried switching the config file from .ts to cypress.config.js and it started to work (syntax needed to be updated to JavaScript as well). I have no idea why.

I started facing this issue, suddenly,
My solution was
rm -rf node_modules package-lock.json
npm i
I already had the cypress.config.ts file, so cypress test runner picked it up, when I ran
npx cypress open

I came across this issue because Typescript was not installed in my Cypress container. When ts-node doesn't have access to typescript, it's require behaves like the native "require", which is why you're seeing the error.

I don't know enough about your specific setup to recommend a solution, but for me I was able to run npm i and mount the volume in the cypress container before running the tests. Another option could be to create a new Dockerfile to extend the base Cypress image with typescript included in the build.

Related