cypress-docker-images icon indicating copy to clipboard operation
cypress-docker-images copied to clipboard

Cypress 10.1.0 and 10.2.0 ERR_UNKNOWN_FILE_EXTENSION typescript

Open Alqio opened this issue 3 years ago • 17 comments
trafficstars

I'm using cypress/included:10.2.0 image to run headless tests on a GitHub action workflow. The following is my cypress docker configuration:

  cypress_headless:
    image: cypress/included:10.2.0
    entrypoint: cypress run --env BASE_URL=front_test:3000 --project .
    working_dir: /app
    networks:
      - cinetwork
    volumes:
      - /tmp/.X11-unix:/tmp/.X11-unix
      - ../front:/app
    environment:
      - DISPLAY
      - CYPRESS_FRONT_URL=front_test:3000
    depends_on:
      - front_test

Locally it runs fine, but on a GitHub action workflow I get the following error when running docker-compose run cypress_headless

Your configFile is invalid: /app/cypress.config.ts

It threw an error when required, check the stack trace below:


TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /app/cypress.config.ts
    at new NodeError (node:internal/errors:371:5)
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:87:11)
    at defaultGetFormat (node:internal/modules/esm/get_format:102:38)
    at defaultLoad (node:internal/modules/esm/load:[21](https://github.com/x/runs/7092451542?check_suite_focus=true#step:4:22):14)
    at ESMLoader.load (node:internal/modules/esm/loader:359:26)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:280:58)
    at new ModuleJob (node:internal/modules/esm/module_job:66:26)
    at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:297:17)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:261:34)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:337:[24](https://github.com/xruns/7092451542?check_suite_focus=true#step:4:25))
    at async importModuleDynamicallyWrapper (node:internal/vm/module:437:15)
    at async loadFile (/root/.cache/Cypress/10.2.0/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_require_async_child.js:106:14)
    at async EventEmitter.<anonymous> (/root/.cache/Cypress/10.2.0/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_require_async_child.js:116:[32](https://github.com/x/runs/7092451542?check_suite_focus=true#step:4:33))

Above that error is another error, but I don't know if it's related:

libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
[192:0628/123716.264172:ERROR:sandbox_linux.cc(377)] InitializeSandbox() called with multiple threads in process gpu-process.
[[19](https://github.com/x/runs/7092451542?check_suite_focus=true#step:4:20)2:0628/123716.276916:ERROR:gpu_memory_buffer_support_x11.cc(44)] dri3 extension not supported.

My project utilizes TypeScript and here is my /app/cypress.config.ts:

import { defineConfig } from 'cypress'

export default defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      // implement node event listeners here
    },
  },
})

I do not have a cypress/index.ts file.

I have tried using both Cypress 10.1.0 and 10.2.0 but neither works. Again, this problem only occurs when running it as a GitHub action.

Alqio avatar Jun 28 '22 12:06 Alqio

The same. but I can locally repeat it.

morriq avatar Jun 30 '22 14:06 morriq

Hello, I had exactly the same problem : everything worked fine locally, I only had the "error unknown file ext..." in github actions. As a workaround, I updated cypress.config.ts to cypress.config.js and converted the file to javascript :

// @todo : rollback to "ts" file and regular import when issue is fixed
module.exports = require('cypress').defineConfig({
  e2e: {/* ... */}
});

The rest of the files are in regular typescript and it is ok. Hope it helps

benjamin-schneider avatar Jul 01 '22 12:07 benjamin-schneider

@benjamin-schneider thanks for posting a temporary workaround. I think #615 could take care of this issue.

admah avatar Jul 01 '22 14:07 admah

I'm facing the same issue with cypress/included:10.3.1 unfortunately renaming config.ts to config.js doesn't seem to suffice. It now complains of the actual tests being a ts file.

mala-rathinasamy avatar Jul 27 '22 10:07 mala-rathinasamy

Same here.

alucardu avatar Aug 03 '22 12:08 alucardu

@alucardu we just released an included image last week with global TS support - cypress/included:10.3.1-typescript. Can you try that and see if it closes this issue?

admah avatar Aug 03 '22 14:08 admah

@admah No, it doesn't work.

It can be easily reproduced:

  1. Create a minimal cypress.config.ts:
import { defineConfig } from 'cypress'

export default defineConfig({})
  1. Try to run Cypress:
docker run -it --rm -v $PWD/cypress.config.ts:/e2e-tests/cypress.config.ts -w /e2e-tests cypress/included:10.3.1-typescript

Output:

libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
[193:0804/110550.272823:ERROR:sandbox_linux.cc(377)] InitializeSandbox() called with multiple threads in process gpu-process.
[193:0804/110550.290577:ERROR:gpu_memory_buffer_support_x11.cc(44)] dri3 extension not supported.
Your configFile is invalid: /e2e-tests/cypress.config.ts

It threw an error when required, check the stack trace below:

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /e2e-tests/cypress.config.ts

....

GarrisonD avatar Aug 04 '22 11:08 GarrisonD

This config is also a valid JS code, so I tried to mount it as mjs:

-... -v $PWD/cypress.config.ts:/e2e-tests/cypress.config.ts ...
+... -v $PWD/cypress.config.ts:/e2e-tests/cypress.config.mjs ...

and the error was:

libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
[196:0804/110833.296407:ERROR:sandbox_linux.cc(377)] InitializeSandbox() called with multiple threads in process gpu-process.
[196:0804/110833.305132:ERROR:gpu_memory_buffer_support_x11.cc(44)] dri3 extension not supported.
Your configFile is invalid: /e2e-tests/cypress.config.mjs

It threw an error when required, check the stack trace below:

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'cypress' imported from /e2e-tests/cypress.config.mjs
...

There is nothing to do with TypeScript. The issue is global...

GarrisonD avatar Aug 04 '22 11:08 GarrisonD

@admah thank you, i've tried that one as well but also didn't work. I ended up with this yml config:



############################
## TEST

test:cypress:
  extends: .base
  image:
    name: cypress/base:14.7.0
    entrypoint: ['']
  stage: test
  script:
    - source .gitlab/scripts/test_cypress.sh
  rules:
    - *branch
// test_cypress.sh
yarn install --frozen-lockfile
yarn add [email protected]
npm run cypress:run:server

alucardu avatar Aug 04 '22 11:08 alucardu

So, the issue is global: missing node_modules in the working dir.

We (users) have two possible solutions here:

  1. Run a super-slow 🐌 npm i/yarn before cypress run that makes cypress/included image absolutely useless 💩
  2. Run a lightning-fast ⚡ ln -s /usr/local/lib/node_modules before cypress run

GarrisonD avatar Aug 04 '22 11:08 GarrisonD

@GarrisonD We can at least skip the download of cypress on install with an env var CYPRESS_INSTALL_BINARY=0. But yes, very slow in my pipeline...

coryasilva avatar Aug 04 '22 14:08 coryasilva

@coryasilva If I planned to run npm i/yarn, I wouldn’t use cypress/included 😆

GarrisonD avatar Aug 04 '22 14:08 GarrisonD

same problem with cypress 10.5.0

deshmaneanup avatar Aug 16 '22 09:08 deshmaneanup

https://stackoverflow.com/questions/73221655/unknown-file-extension-ts-cypress-config-ts-on-ci/73443680#73443680

akshayjai1 avatar Aug 22 '22 10:08 akshayjai1

Happening to me on 10.9 in an NX project

acoreyj avatar Jan 04 '23 22:01 acoreyj

https://stackoverflow.com/questions/73221655/unknown-file-extension-ts-cypress-config-ts-on-ci/73443680#73443680

This answer from akshayjai1 has 2 down votes on Stack Overflow. No explanation though.

odoo-ce-modules avatar Feb 20 '23 15:02 odoo-ce-modules

it would be really nice to solve this issue. @GarrisonD workaround does work but it shouldn't be needed.

we would rather be able to use the cypress/included image as its intended to be. (issue still present in cypress 12.3 image)

KalhindiPOA avatar Mar 09 '23 15:03 KalhindiPOA