Closed brendanHearX closed 2 months ago
@brendanHearX
This may be a problem with your caching. You have replaced the installation and caching otherwise done by cypress-io/github-action
.
In the job cypress-run
you are using npm caching from actions/setup-node
and then npm ci
. This does not cache the Cypress binary. You can try adding npx cypress install
after your npm ci
. This should install the Cypress binary if it is missing.
Thank you for the suggestion and explanation @MikeMcC399.
I tried to install cypress as suggested, but the same error is appearing.
Install Cypress
Run npx cypress@13.7.2 install --force
npm WARN exec The following package was not found and will be installed: cypress@13.7.2
Cypress 13.7.2 is installed in /home/runner/.cache/Cypress/13.7.2
Installing Cypress (version: 13.7.2)
[STARTED] Task without title.
[SUCCESS] Task without title.
[STARTED] Task without title.
[SUCCESS] Task without title.
[STARTED] Task without title.
[SUCCESS] Task without title.
You can now open Cypress by running: node_modules/.bin/cypress open
https://on.cypress.io/installing-cypress
Cypress run
Run cypress-io/github-action@v[6](https://github.com/hearSmart/website-lexie/actions/runs/9756023470/job/26925712499?pr=2748#step:7:7)
Skipping install because install parameter is false
Error: Cannot find module 'cypress'
Require stack:
- /home/runner/work/_actions/cypress-io/github-action/v6/dist/index.js
Updated cypress-run
job:
cypress-run:
runs-on: ubuntu-latest
needs: install
strategy:
fail-fast: false
matrix:
containers: [1, 2]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download the build folder
uses: actions/download-artifact@v4
with:
name: build
- uses: actions/setup-node@v4
with:
node-version: '20.9.0'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Install Cypress
run: npx cypress@13.7.2 install --force
- name: Cypress run
uses: cypress-io/github-action@v6
with:
install: false
record: true
parallel: true
group: 'UI-Chrome'
Screenshot:
@brendanHearX
Is this a private project or is it publicly viewable?
@MikeMcC399 It is a private project
@brendanHearX
Normally the action will install dependencies for you. Is there some reason you are trying to do it by hand?
@brendanHearX
If you want to continue installing dependencies by hand, I would add debug lines
npm ls cypress # to check what version of Cypress you are using
npx cypress verify # to check that everything is installed correctly
also change
npx cypress@13.7.2 install --force # to just
npx cypress install
Your package.json
specifies:
"cypress": "^13.7.2",
so depending on when you ran the npm installation, you may get exactly cypress@13.7.2
or a later version like cypress@13.13.0
which satisfies the semver
requirements.
If you want to use the installation capabilities of the action, then remove the lines:
cache: 'npm'
run: npm ci
run: npx cypress@13.7.2 install --force
install: false
Apart from that you may find that enabling debugging is in the action is helpful.
If you feel this is a bug in cypress-io/github-action
, then please post a full debug log using
env:
DEBUG: '@cypress/github-action'
Thanks again @MikeMcC399 for the support in the debugging and resolving the issue.
The only reason I tried to manually install dependencies was because I was trying to resolve the Cannot find module 'cypress'
error.
I have found and resolved the issue. 🙏 🎉
The problem was in the Download the build folder
step.
Next.js stores it's builds in a .next
folder by default. The download step was taking the contents of that .next
folder and placing it in the root directory, instead of keep the contents within the .next
folder.
This caused issues because one of the files in the .next
folder is an almost empty package.json
file, which was overwriting the original root package.json
file.
I think this resulted in the install process not finding the cypress
dependency to install, and the start
script to run, due to the wrong package.json
existing in the root directory.
I just had to update the download step to store the build files in the .next
folder by specifying the path
, i.e.
- name: Download the build folder
uses: actions/download-artifact@v4
with:
name: build
path: .next # ADDED THIS LINE
The complete workflow file is as follows and now working:
name: Run Cypress Tests on Pull Request
on: pull_request
jobs:
install:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cypress install
uses: cypress-io/github-action@v6
with:
runTests: false
build: npm run build-ssr-staging
- name: Save build folder
uses: actions/upload-artifact@v4
with:
name: build
if-no-files-found: error
path: .next
cypress-run:
runs-on: ubuntu-latest
needs: install
strategy:
fail-fast: false
matrix:
containers: [1, 2]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download the build folder
uses: actions/download-artifact@v4
with:
name: build
path: .next
- name: Cypress run
uses: cypress-io/github-action@v6
with:
record: true
parallel: true
group: 'UI'
start: npm start
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
Congratulations on finding your problem @brendanHearX ! 🎉
It sounds like we can now close this issue.
Issue:
Seeing
Error: Cannot find module 'cypress'
error in GitHub actions logs onCypress run
step:Workflow file:
Folder structure:
package.json: