cypress-io / github-action

GitHub Action for running Cypress end-to-end & component tests
https://on.cypress.io/guides/continuous-integration/github-actions
MIT License
1.37k stars 348 forks source link

Error: Cannot find module 'cypress' #248

Closed chrisdrackett closed 3 years ago

chrisdrackett commented 3 years ago

We just attempted to update to v2 and are now getting the following error when running Cypress. Here is our action config:

jobs:
  end-to-end-tests:
    name: End-to-End tests (web)
    runs-on: ubuntu-latest
    if: github.event.pull_request.draft == false
    steps:
      ## Start Shared Setup
      - name: checkout gather
        uses: actions/checkout@v2

      - name: setup node
        uses: actions/setup-node@v2-beta
        with:
          node-version: 12.18.3

      - uses: bahmutov/npm-install@HEAD
      ## End Shared Setup

      - name: cypress in chrome
        uses: cypress-io/github-action@v2
        with:
          browser: chrome
          headless: true
      - name: upload failure screenshots
        uses: actions/upload-artifact@v2
        if: failure()
        with:
          name: cypress-screenshots
          path: cypress/screenshots
      - name: upload failure videos
        uses: actions/upload-artifact@v2
        if: failure()
        with:
          name: cypress-videos
          path: cypress/videos

and for reference, the previous config:

jobs:
  end-to-end-tests:
    name: End-to-End tests (web)
    runs-on: ubuntu-latest
    if: github.event.pull_request.draft == false
    steps:
      ## Start Shared Setup
      - name: checkout gather
        uses: actions/checkout@v2

      - name: setup node
        uses: actions/setup-node@v2-beta
        with:
          node-version: 12.18.3

      - uses: bahmutov/npm-install@HEAD
      ## End Shared Setup

      - name: cypress in chrome
        uses: cypress-io/github-action@v1
        with:
          browser: chrome
          headless: true
      - name: upload failure screenshots
        uses: actions/upload-artifact@v1
        if: failure()
        with:
          name: cypress-screenshots
          path: cypress/screenshots
      - name: upload failure videos
        uses: actions/upload-artifact@v1
        if: failure()
        with:
          name: cypress-videos
          path: cypress/videos

After running we get the following output:

##[debug]Cypress versions in the cache folder /home/runner/.cache/Cypress
/opt/hostedtoolcache/node/12.18.3/x64/bin/npx cypress cache list
┌─────────┬──────────────┐

│ version │ last used    │
├─────────┼──────────────┤
│ 6.0.0   │ a minute ago │
└─────────┴──────────────┘
##[debug]no need to verify Cypress binary or save caches
##[debug]No start command found
##[debug]Running Cypress tests using NPM module API
##[debug]requiring cypress dependency, cwd is /home/runner/work/calm/calm
##[debug]working directory /home/runner/work/calm/calm
##[debug]Cannot find module 'cypress'
##[debug]Require stack:
##[debug]- /home/runner/work/_actions/cypress-io/github-action/v2/dist/index.js
##[debug]Error: Cannot find module 'cypress'
##[debug]Require stack:
##[debug]- /home/runner/work/_actions/cypress-io/github-action/v2/dist/index.js
##[debug]    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
##[debug]    at Function.resolve (internal/modules/cjs/helpers.js:80:19)
##[debug]    at runTests (/home/runner/work/_actions/cypress-io/github-action/v2/dist/index.js:9094:13)
##[debug]    at processTicksAndRejections (internal/process/task_queues.js:93:5)
Error: Cannot find module 'cypress'
Require stack:
- /home/runner/work/_actions/cypress-io/github-action/v2/dist/index.js
##[debug]Node Action run completed with exit code 1
##[debug]CI='1'
##[debug]CYPRESS_CACHE_FOLDER='/home/runner/.cache/Cypress'
##[debug]CYPRESS_CACHE_FOLDER='/home/runner/.cache/Cypress'
##[debug]CYPRESS_CACHE_FOLDER='/home/runner/.cache/Cypress'
##[debug]TERM='xterm'
##[debug]Finishing: cypress in chrome

The above is with the following added to the action:

  ACTIONS_RUNNER_DEBUG: true
  ACTIONS_STEP_DEBUG: true
bahmutov commented 3 years ago

I have noticed you are using cypress-io/github-action@v1 - can you try the latest cypress-io/github-action@v2 please?

chrisdrackett commented 3 years ago

sorry, I pasted the wrong config! I updated this above with the correct data.

bahmutov commented 3 years ago

This is very weird - can you post the NPM install commands that the action shows while checking the NPM cache and doing the install? There should be a lot more debugging output there before printing the Cypress version

For example, see actions with Cypress v6 running in https://github.com/cypress-io/github-action/actions/runs/381884739 which prints something like this debug output

##[debug]npm cache hit undefined
##[debug]cypress cache hit undefined
##[debug]installing NPM dependencies
##[debug]npm at "/usr/local/bin/npm"
/usr/local/bin/npm ci

> cypress@6.0.0 postinstall /home/runner/work/github-action/github-action/examples/basic/node_modules/cypress
> node index.js --exec install

Note: Overriding Cypress cache directory to: /home/runner/.cache/Cypress

      Previous installs of Cypress may not be found.

Installing Cypress (version: 6.0.0)

25l[20:47:10]  Downloading Cypress     [started]
[20:47:12]  Downloading Cypress     [completed]
[20:47:12]  Unzipping Cypress       [started]
[20:47:20]  Unzipping Cypress       [completed]
[20:47:20]  Finishing Installation  [started]
[20:47:20]  Finishing Installation  [completed]
25h
You can now open Cypress by running: node_modules/.bin/cypress open

on.cypress.io/installing-cypress

25hadded 216 packages in 14.709s
##[debug]Cypress versions in the cache folder /home/runner/.cache/Cypress
/usr/local/bin/npx cypress cache list
┌─────────┬──────────────┐
│ version │ last used    │
├─────────┼──────────────┤
│ 6.0.0   │ 21 hours ago │
└─────────┴──────────────┘
##[debug]Verifying Cypress using cache folder /home/runner/.cache/Cypress
/usr/local/bin/npx cypress verify

25l[20:47:22]  Verifying Cypress can run /home/runner/.cache/Cypress/6.0.0/Cypress [started]
[20:47:24]  Verifying Cypress can run /home/runner/.cache/Cypress/6.0.0/Cypress [completed]
25h25h::debug::saving NPM modules
##[debug]Hash from file /home/runner/work/github-action/github-action/examples/basic/package-lock.json is 3cfa0efc12214f86fc9b47870f2422521e27f66ff223a7c2142233f45d2498bcb31d6938612fc8839a98589d0226139c91454ec169f33f60ed8626aee21613fe
##[debug]Checking zstd --version
##[debug]*** zstd command line interface 64-bits v1.3.3, by Yann Collet ***
##[debug]Reserving Cache
##[debug]Resource Url: artifactcache.actions.githubusercontent.com/cuiKCbVynhhThBP4DaiMx33Cvu2ggPk7WDHl4JAx3XbFskrx6i/_apis/artifactcache/caches
##[debug]Cache ID: 1483
##[debug]implicitDescendants 'false'
##[debug]followSymbolicLinks 'true'
##[debug]implicitDescendants 'false'
##[debug]omitBrokenSymbolicLinks 'true'
##[debug]Search path '/home/runner/.npm'
##[debug]Matched: ../../../.npm
##[debug]Cache Paths:
##[debug]["../../../.npm"]
##[debug]Archive Path: /home/runner/work/_temp/1714437c-8c43-4322-a93d-c3681def9163/cache.tzst
/bin/tar --posix --use-compress-program zstd -T0 -cf cache.tzst -P -C /home/runner/work/github-action/github-action --files-from manifest.txt
##[debug]File Size: 4899030
##[debug]Saving Cache (ID: 1483)
##[debug]Upload cache
##[debug]Resource Url: artifactcache.actions.githubusercontent.com/cuiKCbVynhhThBP4DaiMx33Cvu2ggPk7WDHl4JAx3XbFskrx6i/_apis/artifactcache/caches/1483
##[debug]Upload concurrency: 4
##[debug]Upload chunk size: 33554432
##[debug]Awaiting all uploads
##[debug]Uploading chunk of size 4899030 bytes at offset 0 with content range: bytes 0-4899029/*
##[debug]Commiting cache
##[debug]Resource Url: artifactcache.actions.githubusercontent.com/cuiKCbVynhhThBP4DaiMx33Cvu2ggPk7WDHl4JAx3XbFskrx6i/_apis/artifactcache/caches/1483
Cache saved successfully
##[debug]saving Cypress binary
##[debug]Hash from file /home/runner/work/github-action/github-action/examples/basic/package-lock.json is 3cfa0efc12214f86fc9b47870f2422521e27f66ff223a7c2142233f45d2498bcb31d6938612fc8839a98589d0226139c91454ec169f33f60ed8626aee21613fe
##[debug]Checking zstd --version
##[debug]*** zstd command line interface 64-bits v1.3.3, by Yann Collet ***
##[debug]Reserving Cache
##[debug]Resource Url: artifactcache.actions.githubusercontent.com/cuiKCbVynhhThBP4DaiMx33Cvu2ggPk7WDHl4JAx3XbFskrx6i/_apis/artifactcache/caches
##[debug]Cache ID: 1484
##[debug]implicitDescendants 'false'
##[debug]followSymbolicLinks 'true'
##[debug]implicitDescendants 'false'
##[debug]omitBrokenSymbolicLinks 'true'
##[debug]Search path '/home/runner/.cache/Cypress'
##[debug]Matched: ../../../.cache/Cypress
##[debug]Cache Paths:
##[debug]["../../../.cache/Cypress"]
##[debug]Archive Path: /home/runner/work/_temp/89af4165-4fd9-452f-b3de-9b1e3d6f8400/cache.tzst
/bin/tar --posix --use-compress-program zstd -T0 -cf cache.tzst -P -C /home/runner/work/github-action/github-action --files-from manifest.txt
##[debug]File Size: 174492593
##[debug]Saving Cache (ID: 1484)
##[debug]Upload cache
##[debug]Resource Url: artifactcache.actions.githubusercontent.com/cuiKCbVynhhThBP4DaiMx33Cvu2ggPk7WDHl4JAx3XbFskrx6i/_apis/artifactcache/caches/1484
##[debug]Upload concurrency: 4
##[debug]Upload chunk size: 33554432
##[debug]Awaiting all uploads
##[debug]Uploading chunk of size 33554432 bytes at offset 0 with content range: bytes 0-33554431/*
##[debug]Uploading chunk of size 33554432 bytes at offset 33554432 with content range: bytes 33554432-67108863/*
##[debug]Uploading chunk of size 33554432 bytes at offset 67108864 with content range: bytes 67108864-100663295/*
##[debug]Uploading chunk of size 33554432 bytes at offset 100663296 with content range: bytes 100663296-134217727/*
##[debug]Uploading chunk of size 33554432 bytes at offset 134217728 with content range: bytes 134217728-167772159/*
##[debug]Uploading chunk of size 6720433 bytes at offset 167772160 with content range: bytes 167772160-174492592/*
##[debug]Commiting cache
##[debug]Resource Url: artifactcache.actions.githubusercontent.com/cuiKCbVynhhThBP4DaiMx33Cvu2ggPk7WDHl4JAx3XbFskrx6i/_apis/artifactcache/caches/1484
Cache saved successfully
##[debug]building application using "npx cypress info"
build app command "npx cypress info"
current working directory "/home/runner/work/github-action/github-action/examples/basic"
##[debug]parsed command: npx cypress info
##[debug]found command "/usr/local/bin/npx"
##[debug]with arguments cypress info
##[debug]running "/usr/local/bin/npx" cypress info in /home/runner/work/github-action/github-action/examples/basic
##[debug]without waiting for the promise to resolve
/usr/local/bin/npx cypress info
Displaying Cypress info...

Detected 2 browsers installed:

1. Chrome
  - Name: chrome
  - Channel: stable
  - Version: 86.0.4240.198
  - Executable: google-chrome

2. Firefox
  - Name: firefox
  - Channel: stable
  - Version: 82.0.3
  - Executable: firefox

Note: to run these browsers, pass <name>:<channel> to the '--browser' field

Examples:
- cypress run --browser firefox
- cypress run --browser chrome

Learn More: on.cypress.io/launching-browsers

Proxy Settings: none detected
Environment Variables:
CYPRESS_CACHE_FOLDER: /home/runner/.cache/Cypress

Application Data: /home/runner/.config/cypress/cy/development
Browser Profiles: /home/runner/.config/cypress/cy/development/browsers
Binary Caches: /home/runner/.cache/Cypress

Cypress Version: 6.0.0
System Platform: linux (Ubuntu - 18.04)
System Memory: 7.29 GB free 4.13 GB
##[debug]No start command found
##[debug]Running Cypress tests using NPM module API
##[debug]requiring cypress dependency, cwd is /home/runner/work/github-action/github-action
##[debug]working directory /home/runner/work/github-action/github-action/examples/basic
##[debug]resolved cypress /home/runner/work/github-action/github-action/examples/basic/node_modules/cypress/index.js
##[debug]Cypress options {"headless":false,"record":false,"parallel":false,"quiet":false,"configFile":"cypress.json"}

====================================================================================================

  (Run Starting)
...
chrisdrackett commented 3 years ago

@bahmutov Could this be because we don't have cypress as a dependency for our project? To run tests locally we do npx cypress run.

bahmutov commented 3 years ago

wait, Cypress is not dev dependency? It really should be ...

chrisdrackett commented 3 years ago

I added it and that worked. For some reason when we were using v1 of this package we had failures and ended up removing it. I don't remember the details as it was in April, but we seem good now!

bahmutov commented 3 years ago

Super, I will keep this issue open, will add a note to README about having cypress as a dev dependency

mikenikles commented 3 years ago

I was forced to upgrade to v2 due to the set-env command that is now throwing an error vs. previously when it was a warning. So overall, it's a good thing it broke and forced me to upgrade :).

My Cypress tests run against a live URL, so I set install: false and didn't install any dependencies. With cypress required as a dev dependency, it looks like I now have to install my dependencies to run Cypress tests.

🤔 or... what about the following to install the cypress dependency only. Too ugly?

with:
  build: npm i -D cypress

Update: Tested that and it works. See https://github.com/mikenikles/www-mikenikles-com/pull/249

bahmutov commented 3 years ago

@chrisdrackett I have added a comment to the README about having cypress as dependency.

@mikenikles I see your use case, I have described it in https://glebbahmutov.com/blog/develop-preview-test/ The problem you have (as I have in https://github.com/bahmutov/eleventy-example) is that the caching is not working in this case, and it re-installs Cypress again and again.

But even aside from this, seems post-deploy event is different on GH Actions and does NOT have the right user to restore the cache at all. I see this in https://github.com/bahmutov/eleventy-example/runs/1446015796?check_suite_focus=true for example

Screen Shot 2020-11-25 at 9 26 25 AM

So I don't know what to do in this case :) Maybe we could use https://github.com/cypress-io/cypress-docker-images/tree/master/included Docker image to have Cypress pre-installed?

I have opened https://github.com/bahmutov/eleventy-example/issues/23 - if that works, I will update an example in this repo with this workaround. But I agree - it would be nice to have an advanced example or flag that says "do not install any dependencies, just Cypress, but cache it". It could be even manual caching YML in combination with this action.

bahmutov commented 3 years ago

Ok, I added an example installing just Cypress dependency, but you have to cache it using separate commands, see https://github.com/cypress-io/github-action/blob/master/.github/workflows/example-install-only.yml

github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 2.7.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

mikenikles commented 3 years ago

Thanks for the example, it dropped my action execution time from 1m 12s to 50s 🚀.

janharmenwind commented 2 years ago

I'm experiencing the same error message. I used chrisdrackett's code and installed the npm package. I've got no idea where to look now.

jobs:
  end-to-end-tests:
    name: End-to-End tests (web)
    runs-on: windows-latest
    if: github.event.pull_request.draft == false
    steps:
      ## Start Shared Setup
      - name: checkout gather
        uses: actions/checkout@v2

      - name: setup node
        uses: actions/setup-node@v2-beta
        with:
          node-version: 12.18.3

      - uses: bahmutov/npm-install@HEAD
      ## End Shared Setup

      - name: cypress in chrome
        uses: cypress-io/github-action@v2
        with:
          browser: chrome
          headless: true
┌─────────┬────────────┐
│ version │ last used  │
├─────────┼────────────┤
│ 9.3.1   │ 2 days ago │
└─────────┴────────────┘
Error: Cannot find module 'cypress'
Require stack:
- D:\a\_actions\cypress-io\github-action\v2\dist\index.js
janharmenwind commented 2 years ago

The caching happens on the D:-drive which doesn't exist on this pc. Could that be problem and how can I change the drive letter?