首页 > 解决方案 > 为什么我的 .gitlab-ci.yml 在纱线测试中不断失败,并出现错误“/bin/sh: 1: react-scripts: not found”?

问题描述

在这里,我有一个使用 npx create-react-app 创建的简单反应应用程序。

管道成功提取缓存但失败yarn test --watchAll=false并出现错误“/bin/sh: 1: react-scripts: not found”。

我该如何解决?。

react 应用程序位于 src/client 目录中,因此 before_script 到 cd 在正确的目录中,如下面的 yml 文件所示。

.gitlab-ci.yml:

image: node:latest

default:
  before_script:
    - cd src/client

stages:
  - build
  - test

cache:
  paths:
    - node_modules/

build_react:
  stage: build
  script:
    - yarn install
    - yarn build
  artifacts:
    expire_in: 1 hour
    paths:
      - build

test_react:
  stage: test
  script:
    - pwd
    - yarn test --watchAll=false

标签: continuous-integrationgitlabgitlab-cinode-modulesyarnpkg

解决方案


在运行任何脚本之前下载并提取工件,因此它将被提取到{project_root}/,然后您的默认 before_script 将运行。您应该能够通过 引用构建目录../../build,或将其移动到src/client您的test_react工作中。


推荐阅读