我正在尝试构建一个包含github操作的CI/CD管道,以便构建并部署我的应用程序到heroku。我用跟踪YAML文件。但它显示了github操作中的错误。有人能帮我解决这个问题吗?我的存储库是大商店.My项目结构是bigshop \-backend x-前端-Package.json
错误-
Run npm run buildsh: 1: react脚本:找不到
国家预防机制错误!代码ELIFECYCLE npm错误!syscall产生了npm错误!文件sh npm错误!错误,错误,错误!前端@0.1.0构建:react-scripts build npm!产卵
bigshop@1.0.0 build /home/runner/work/bigshop cd /bigshop cd前端& npm运行构建前端@0.1.0构建/home/runner/work/bigshopcicd/bigshopcicd/frontend react脚本构建
国家预防机制错误!国家预防机制错误!前端@0.1.0构建脚本失败。国家预防机制错误!这可能不是npm的问题。上面可能还有额外的日志输出。npm警告本地package.json存在,但node_modules缺失,您是否打算安装?
国家预防机制错误!此运行的完整日志可以在以下位置找到: npm ERR!/home/runner/.npm/_logs/2021-12-23T08_13_25_954Z-debug.log npm!代码ELIFECYCLE npm错误!错误1国家预防机制错误!bigshop@1.0.0构建:cd frontend && npm run build npm!退出状态1 npm错误!国家预防机制错误!在bigshop@1.0.0构建脚本中失败。国家预防机制错误!这可能不是npm的问题。上面可能还有额外的日志输出。
国家预防机制错误!此运行的完整日志可以在: npm!/home/runner/.npm/_logs/2021-12-23T08_13_25_975Z-debug.log错误:使用退出代码1完成的过程中找到。
pipeline.yml-
name: Deployment pipeline
on:
push:
branches:
- main
pull_request:
branches: [main]
types: [opened, synchronize]
jobs:
simple_deployment_pipeline:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12.x'
- name: npm install
run: npm install
- name: build
run: npm run build
- name: deployment
uses: akhileshns/heroku-deploy@v3.12.12
if: ${{ github.event_name == 'push' && !contains(join(github.event.commits.*.message, ' ,'), '#skip') }}
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: bigshopcicd
heroku_email: fakirsumon78@gmmail.com
healthcheck: 'https://bigshopcicd.herokuapp.com/health'
checkstring: 'ok'
rollbackonhealthcheckfailed: true
- uses: actions/checkout@v2
- name: Bump version and push tag
uses: anothrNick/github-tag-action@eca2b69f9e2c24be7decccd0f15fdb1ea5906598
if: ${{ github.event_name == 'push' && !contains(join(github.event.commits.*.message, ' ,'), '#skip') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true
DEFAULT_BUMP: patch
RELEASE_BRANCHES: mainpackage.json文件-
"scripts": {
"start": "node backend/server.js",
"dev": "set NODE_ENV=DEVELOPMENT& nodemon backend/server",
"prod": "set NODE_ENV=PRODUCTION& nodemon backend/server",
"seeder": "node backend/utils/seeder.js",
"build": "cd frontend && npm run build",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false && npm install --prefix frontend && npm run build --prefix frontend"},
发布于 2021-12-23 08:59:48
npm命令在根package.json中运行安装,它不包含响应依赖项。然后,构建步骤进入./前端,并尝试使用那些未获取的响应脚本。
您可以使用npm的preinstall目标来安装前端依赖项。
另外,尝试看看是否有可能将项目分成两种不同的结构,因为这种结构看起来很脆弱,而且实际上失去了拥有单独的后端/前端的优势。(加上您的脚本变得过于复杂)
编辑:
预安装不是专门为安装节点模块而做的,它只是一个可以添加到package.json中的步骤,在安装步骤之前由npm运行,它可以包含任意脚本命令。在你的情况下,可以尝试:
"scripts": {
"preinstall": "cd frontend && npm install",
"start": "node backend/server.js",
"dev": "set NODE_ENV=DEVELOPMENT& nodemon backend/server",
"prod": "set NODE_ENV=PRODUCTION& nodemon backend/server",
"seeder": "node backend/utils/seeder.js",
"build": "cd frontend && npm run build"
}https://stackoverflow.com/questions/70459512
复制相似问题