[英]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.