简体   繁体   English

在 Gitlab CI runner / Google Cloud 中创建 React 应用程序构建失败

[英]Create react app build failed in Gitlab CI runner / Google cloud

I have a create react app with docker which is running fine on my local machine.我有一个带有 docker 的 create react 应用程序,它在我的本地机器上运行良好。 If I run Gitlab CI runner locally, the command npm build succeed.如果我在本地运行 Gitlab CI runner,命令npm build成功。 But if I do the same command in remote server ( Gitlab CI / Google Cloud) , it always fails with the following message :但是如果我在远程服务器(Gitlab CI / Google Cloud)中执行相同的命令,它总是失败并显示以下消息:

./src/assets/img/logo_blue.png  
Error: Cannot find module './validate'

The problem seems not to be related to related to this issue : Why is Create React App build failing in Gitlab CI Runner?问题似乎与此问题无关: Why is Create React App build failed in Gitlab CI Runner? . . From the error message, I can guess a path problem.从错误信息中,我可以猜测路径问题。 For some reasons, inside Gitlab CI runner the path: src is pointing to not my react app src folder.由于某些原因,在 Gitlab CI runner 中,路径:src 指向的不是我的 react app src 文件夹。

Should I set the root path somewhere?我应该在某处设置根路径吗? The configuration is as follows:配置如下:

Docker码头工人

FROM node:10.16-alpine as build-deps
WORKDIR /app
COPY package*.json ./
COPY yarn.lock ./

RUN npm install
COPY . .
RUN npm run build

#ngnix server
# artifact is recheable on port 80
FROM nginx:1.13.12-alpine
# expose port 
EXPOSE 80
# perms to write 
RUN set -x ; \
    addgroup -g 82 -S www-data ; \
    adduser -u 82 -D -S -G www-data www-data && exit 0 ; exit 1

RUN chown -R www-data:www-data /usr/share/nginx/html/*
RUN chmod -R 0755 /usr/share/nginx/html/*

# use conf.d to handle redirect aka reload point to root index.html
COPY ./default.conf /etc/nginx/conf.d/default.conf 

#copy assets
COPY --from=build-deps /app/build  /usr/share/nginx/html
# command
CMD ["nginx", "-g", "daemon off;"]

my gitlab ci is我的 gitlab ci 是

image: node:10
cache:
  key: build-cache
  paths:
    - node_modules/
    - /root/.npm/_logs
stages:
  - build

## build

build:master:
  image: docker:19.03.1
  #image: tmaier/docker-compose:latest
  stage: build
  only:
    - dev
    - master
  allow_failure: false
  variables:
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: "/certs"
  services:
    - docker:19.03.1-dind
  before_script:
    # docker login -u $DOCKER_KEY -p $DOCKER_ACCESS
  script:
    - docker build  -f ./client/Dockerfile ./client
    # - docker-compose up --build --no-start
    #- docker build -t $DOCKER_CLIENT_TAG -f ./client/Dockerfile ./client
    #- docker build -t $DOCKER_PROXY_TAG -f ./proxy/Dockerfile ./proxy
    #- docker push $DOCKER_CLIENT_TAG
    #- docker push $DOCKER_PROXY_TAG




and the jsx file looks like this和 jsx 文件看起来像这样


import BlueLogo from "./../../../assets/img/logo_blue.png";

In the tsconfig.json, just add "baseUrl": "./".在 tsconfig.json 中,只需添加 "baseUrl": "./"。
For some reason, on my local machine, typescript could resolve the path without explicit configuration but failed on remote出于某种原因,在我的本地机器上,打字稿可以在没有显式配置的情况下解析路径,但在远程失败

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 GITLAB CI - React 应用程序构建失败但工作成功 - GITLAB CI - React app build failed but job success 将create-react-app构建部署到Google Cloud Platform后找不到URL - URLs not found after deploying create-react-app build to Google Cloud Platform 在 gitlab runner 上使用 asar 构建的 React Electron 应用程序会产生 JavaScript 错误 - React Electron App built with asar on gitlab runner creates JavaScript errors 使用gitlab-ci部署react app的最佳方法? - Best way to deploy react app with gitlab-ci? 如何将create-react-app部署到Google Cloud - How to deploy create-react-app to Google Cloud 我可以将环境变量从 Gitlab.gitlab-ci.yml 传递给 React 应用程序吗? - Can I pass environment variables from Gitlab .gitlab-ci.yml to a React app? 在Google云中部署react app - Deploying react app in google cloud 为什么我收到错误:运行 npm ci & run npm 构建失败时,将更改推送到部署在 Firebase 上的 React 应用程序? - Why do I get error: run npm ci & run npm build failed when pushing changes to React app that is deployed on Firebase? 为什么反应应用程序 jsconfig.json 不适用于 gitlab ci/cd 管道与 creat-react-app? - Why react app jsconfig.json is not working with gitlab ci/cd pipeline with creat-react-app? 用于 GAE 的 React App + Node Gitlab cicd 管道(构建和部署) - React App + Node Gitlab cicd pipeline for GAE (Build and Deploy)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM