Skip to content
Advertisement

Cypress is not running in ci SyntaxError: Unexpected token ‘export’ with cypress-io/github-action@v2 typescript

I have the following plugin file for cypress: frontend/cypress/plugins/index.ts:

export default ((on, config) => {
  // `on` is used to hook into various events Cypress emits
  // `config` is the resolved Cypress config
}) as Cypress.PluginConfig

When I run it on my machine it’s working but when I use cypress-io/github-action@v2 in my github actions I get the following error:

Your pluginsFile is invalid: /home/runner/work/XX/XX/frontend/cypress/plugins/index.ts

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

/home/runner/work/XX/XX/frontend/cypress/plugins/index.ts:14
export default ((on, config) => {
^^^^^^
SyntaxError: Unexpected token 'export'

This is my .github/workflows/cypress-tests.yml:

name: Cypress Tests

jobs:
  cypress-run:
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
    
      - name: Install dependencies
        run: | 
          cd frontend  
          npm ci
                
      - name: Cypress run
        uses: cypress-io/github-action@v2
        with:
          working-directory: frontend
          start: npm run serve
          wait-on: 'http://localhost:8080'  

My frontend/cypress.json config file is empty. This is my frontend/cypress/tsconfig.json in the cypress folder:

{
    "include": [
        "./integration/**/*",
        "./support/**/*"
    ],
    "compilerOptions": {
        "isolatedModules": false,
        "target": "es5",
        "lib": [
            "es5",
            "dom"
        ],
        "types": [
            "cypress"
        ]
    }
}

This frontend/cypress/plugins/tsconfig.jsonis inside the Plugins folder:

{
    "include": [
        "./**/*"
    ],
    "compilerOptions": {
        "module": "CommonJS",
        "preserveValueImports": false,
        "types": [
            "node",
            "cypress/types/cypress"
        ]
    }
}

I have copied this configuration from npm init vue@latest with typescript and cypress.

What’s the problem?

Advertisement

Answer

I forgot to add typescript to my dependencies:

npm install typescript --save-dev
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement