Error: Cannot find module 'cypress': fail to run action on pnpm workspace.
markoleavy opened this issue · comments
I have a monorepo that uses pnpm workspace, structured like that
├── packages
│ ├── various services folders
│ └── test
│ ├── cypress
│ │ └── cypress folders
│ ├── cypress.config.js
│ └── package.json
├── node_modules
├── package.json
├── pnpm-lock.yaml
└── other files
This is my job setup:
jobs:
build-and-test:
runs-on: ubuntu-22.04
name: Build and test
steps:
- name: Checkout Code
uses: actions/checkout@v3
# installing pnpm and node as explained on official pnpm website
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
run_install: false
- name: Setup Node 18
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'pnpm'
- name: Install dependencies
run: |
pnpm i --frozen-lockfile
# other tasks running here
- name: Run test
uses: cypress-io/github-action@v6
with:
project: ./packages/test/
browser: chrome
I also tried this cache config as suggested on PR #1043
jobs:
build-and-test:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Run test
uses: cypress-io/github-action@v6
with:
project: ./packages/test/
browser: chrome
That the log that the Run test action returns:
/home/runner/setup-pnpm/node_modules/.bin/pnpm install --frozen-lockfile
Scope: all 16 workspace projects
Lockfile is up to date, resolution step is skipped
Already up to date
Done in 3.4s
/opt/hostedtoolcache/node/18.12.1/x64/bin/npx cypress cache list
npm WARN exec The following package was not found and will be installed: cypress@13.3.1
┌─────────┬────────────┐
│ version │ last used │
├─────────┼────────────┤
│ 13.3.1 │ 2 days ago │
└─────────┴────────────┘
/opt/hostedtoolcache/node/18.12.1/x64/bin/npx cypress verify
[STARTED] Task without title.
[SUCCESS] Task without title.
/usr/bin/tar --posix -cf cache.tzst --exclude cache.tzst -P -C /home/runner/work/reponame/reponame --files-from manifest.txt --use-compress-program zstdmt
Cache Size: ~19 MB (19807[41](https://github.com/org/reponame/actions/runs/6516571247/job/17700248539#step:27:42)5 B)
Cache saved successfully
/usr/bin/tar --posix -cf cache.tzst --exclude cache.tzst -P -C /home/runner/work/reponame/reponame --files-from manifest.txt --use-compress-program zstdmt
Cache Size: ~157 MB (16[45](https://github.com/org/reponame/actions/runs/6516571247/job/17700248539#step:27:46)55703 B)
Cache saved successfully
Error: Cannot find module 'cypress'
Require stack:
- /home/runner/work/_actions/cypress-io/github-action/v6/dist/index.js
I'm using Cypress 13.3.1 and that the config file
/* eslint-disable @typescript-eslint/no-unused-vars */
const { defineConfig } = require('cypress');
module.exports = defineConfig({
chromeWebSecurity: false,
fixturesFolder: false,
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
supportFile: false,
},
});
The action does not have any special code to handle pnpm workspaces. This is only in place for Yarn workspaces.
You can try adding the install: false
parameter like this:
- name: Run test
uses: cypress-io/github-action@v6
with:
install: false
project: ./packages/test/
browser: chrome
You are already installing dependencies separately using
- name: Install dependencies
run: |
pnpm i --frozen-lockfile
Also, I wouldn't expect there to be a pnpm-lock.yaml
file in the packages/test
directory if this is a regular workspace setup.
If that doesn't work, then it would be helpful if you could share a complete repository setup (minimum reproducible example) online. If you cannot do that then I can share an example pnpm workspace project which works, however that is not identical to your structure.
Let us know how you progress!
Hi @MikeMcC399, thanks for your quick answer.
I've tried to put install: false
even before posting here, but the result is just that it goes straight to:
Run cypress-io/github-action@v6
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
Also, I wouldn't expect there to be a pnpm-lock.yaml file in the packages/test directory if this is a regular workspace setup.
There isn't one in fact, I just have the one in the main folder.
Here you can find a repository setup project. https://github.com/markoleavy/cypress-test.git
Thanks!
Many thanks for your repo. I can see your issues directly now.
The workflow has two problems:
-
The parameter
project
assumes that you have Cypress installed in the root of your repo. Because of this, the action fails to find Cypress to run it. Unfortunately Cypress does not document this well under https://docs.cypress.io/guides/guides/command-line#cypress-run-project-lt-project-path-gt. -
actions/setup-node@v3
is cachingpnpm
, however the Cypress binary cache is not being cached, so this would work the first time but not the second time, becausepnpm install --frozen-lockfile
would not run the post-install script to install the Cypress binary
To resolve:
- Change the
project
parameter toworking-directory
. - You can either remove the pnpm caching or add caching of the Cypress binary cache.
To cache the Cypress binary cache you can add the following before the pnpm install
step:
- name: Set up Cypress binary cache
uses: actions/cache@v3
with:
path: ~/.cache/Cypress
key: cypress-${{ runner.os }}-cypress-${{ hashFiles('pnpm-lock.yaml') }}
- I've given you a PR markoleavy/cypress-test#1 to fix the workflow.
The PR markoleavy/cypress-test#1 merged successfully into your demo repo, so unless there is anything else open for you I would suggest to close the issue here.
Hello @MikeMcC399.
Thanks for your answer, your solution worked perfectly. Hope this might be helpful for other pnpm workspace users.
Cheers!
I updated the version string in a package in my pnpm workspace and cypress, that worked fine before, started failing on the binary being missing. Tried adding both cypress cache, pnpm cache and working-dir
to no avail. Any ideas? 🤯 tidal-music/tidal-sdk-web#80
To keep the issues clean, please open a new one. Thanks for providing your repo link, that is always very helpful for troubleshooting.
To keep the issues clean, please open a new one. Thanks for providing your repo link, that is always very helpful for troubleshooting.
Created a new one: #1138