reactjsyamlcypressgithub-actionsserve

How do I fix this error given by yarn serve -s build


I'm using GitHub actions to run my cypress tests automatically on every commit. This is the part of code in my yml file which was working earlier:

with:
  browser: chrome
  build: yarn run build
  start: yarn start
  wait-on: 'http://localhost:3000'

Then to use serve I made changes in 2 lines:

with:
  browser: chrome
  run: yarn global add serve //added this line
  build: yarn run build
  start: yarn serve -s build //changed this line
  wait-on: 'http://localhost:3000'

Now instead of running the test, it shows this error:

Warning: Unexpected input(s) 'run', valid inputs are ['record', 'config', 'config-file', 'env', 'browser', 'command', 'start', 'start-windows', 'build', 'install', 'install-command', 'runTests', 'wait-on', 'wait-on-timeout', 'parallel', 'group', 'tag', 'working-directory', 'headed', 'spec', 'project', 'command-prefix', 'ci-build-id', 'cache-key', 'quiet', 'component']

&

Error: Unable to locate executable file: serve. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.

So how do I fix this?

Also if I use start: npx serve -s build instead of yarn serve -s build, it works but it is a yarn project and I think I'm not suppose to use npm and npx in yarn projects, right? Or can I?


Solution

  • with:
      browser: chrome
      build: yarn run build
      start: yarn serve
      wait-on: 'http://localhost:3000'
    

    in package.json

    {
      "scripts": {
        "serve": "serve -s build"
      }
    }