github-action
                                
                                 github-action copied to clipboard
                                
                                    github-action copied to clipboard
                            
                            
                            
                        Error finding package-lock.json within npm workspace
I have a monorepo using npm workspaces.
This action worked with lerna + yarn workspaces, but is failing after switching to npm workspaces.
It seems that restoreCachedNpm is trying to find a lock file in one of the workspaces, and throwing an error when it can't find it.
My workflow config is as follows:
      - uses: cypress-io/github-action@v2
        with:
          working-directory: packages/example-application
          command: npm exec cypress run-ct
The stack trace is as follows:
Error: ENOENT: no such file or directory, open '/home/runner/work/govuk-react/govuk-react/packages/example-application/package-lock.json'
12
    at Object.openSync (fs.js:440:3)
13
    at Object.readFileSync (fs.js:342:35)
14
    at Function.module.exports.hasha.fromFileSync (/home/runner/work/_actions/cypress-io/github-action/v2/dist/index.js:17725:54)
15
    at lockHash (/home/runner/work/_actions/cypress-io/github-action/v2/dist/index.js:6796:26)
16
    at getNpmCache (/home/runner/work/_actions/cypress-io/github-action/v2/dist/index.js:6806:16)
17
    at restoreCachedNpm (/home/runner/work/_actions/cypress-io/github-action/v2/dist/index.js:6853:21)
18
    at installMaybe (/home/runner/work/_actions/cypress-io/github-action/v2/dist/index.js:7434:5)
19
    at Object.<anonymous> (/home/runner/work/_actions/cypress-io/github-action/v2/dist/index.js:7459:1)
20
    at __webpack_require__ (/home/runner/work/_actions/cypress-io/github-action/v2/dist/index.js:24:31)
21
    at startup (/home/runner/work/_actions/cypress-io/github-action/v2/dist/index.js:43:19) {
22
  errno: -2,
23
  syscall: 'open',
24
  code: 'ENOENT',
25
  path: '/home/runner/work/govuk-react/govuk-react/packages/example-application/package-lock.json'
26
This was from a build against this commit
https://github.com/govuk-react/govuk-react/pull/850/commits/eb33488d02cfb7c3dab7a30d9f79bc76e910a8de
The build is at
https://github.com/govuk-react/govuk-react/runs/2651634237
This is related to https://github.com/cypress-io/github-action/issues/145 but is related to a monorepo structure rather than lock file name.
This is odd, it worked perfectly fine ~2 month ago. I had my pipeline for e2e off, now I am getting the same issue. I even backtraced with cypress-io/[email protected] that I am sure back then worked.
I am also using lerna & yarn workspace, not npm
my config is
      - name: Cypress run
        uses: cypress-io/[email protected]
        with:
          install-command: yarn --frozen-lockfile --non-interactive
          start: yarn start:<myApp>
          project: ./packages/apps/<myApp>
          spec: packages/apps/<myApp>/cypress/integration/**/*.js
          wait-on: 'http://localhost:3000'
          wait-on-timeout: 120
          record: true
        env:
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Error: ENOENT: no such file or directory, open '/__w/<myreponame>/<myreponame>/package-lock.json'
    at Object.openSync (fs.js:440:3)
    at Object.readFileSync (fs.js:342:35)
Anyone knows a workaround?
Same problem here.

Yeah, I'm getting the same: ` Run cypress-io/github-action@v2 internal/fs/utils.js:220 throw err; ^
Error: ENOENT: no such file or directory, open '/home/runner/work/myapp/myapp/package-lock.json' `
I opened a draft PR https://github.com/cypress-io/github-action/pull/382 for this but have gone with a workaround instead.
I think the best option is to manage the npm install yourself via your github action, and then to pass install: false to cypress-io/github-action as suggested at https://github.com/cypress-io/github-action/issues/145#issuecomment-884808726
- Error handling when no lock file is found was improved through PR https://github.com/cypress-io/github-action/pull/848 so it should now be possible to understand the error and provide a lockfile in the correct location.