You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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文件,结合仓库内容分析:

  1. 仓库中没有package.json文件——这是npm项目的核心配置文件,npm ci依赖它来识别并安装依赖;
  2. 仓库中也没有工作流里指定的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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 16:43:19