GitHub Actions构建报错:exit code 254及package.json缺失求助
GitHub Actions 构建网站报错排查
工作流配置
name: Node.js CI on: push: branches: [ main ] pull_request: branches: [ main ] jobs: build: runs-on: ubuntu-latest strategy: matrix: node-version: [14.x] steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - name: Install dependencies run: npm ci - name: Run script run: node script.js
报错信息
Run npm ci npm ci shell: /usr/bin/bash -e {0} npm ERR! code ENOENT npm ERR! syscall open npm ERR! path /home/runner/work/GiBillOverseas/GiBillOverseas/package.json npm ERR! errno -2 npm ERR! enoent ENOENT: no such file or directory, open '/home/runner/work/GiBillOverseas/GiBillOverseas/package.json' npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent npm ERR! A complete log of this run can be found in: npm ERR! /home/runner/.npm/_logs/2024-02-22T20_05_45_180Z-debug.log Error: Process completed with exit code 254.
排查与解决方案
从报错信息能明确看到,npm ci命令找不到package.json文件,结合仓库内容分析:
- 仓库中没有
package.json文件——这是npm项目的核心配置文件,npm ci依赖它来识别并安装依赖; - 仓库中也没有工作流里指定的
script.js文件,即便依赖安装成功,后续node script.js步骤也会报错。
解决步骤:
- 若你的项目是Node.js项目,先在本地运行
npm init -y生成package.json,根据需求添加依赖和脚本命令; - 确保
script.js文件存在,且内容符合你的构建需求; - 将
package.json、script.js及其他必要项目文件提交推送到GitHub仓库; - 若你的项目不是Node.js项目,需修改工作流配置,替换为适配当前项目的构建步骤(比如静态网站可直接部署,无需Node.js相关流程)。
内容的提问来源于stack exchange,提问作者Alex McVay
相关产品推荐
相关产品推荐

