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

Github Actions中npm ci执行失败:无法读取@auth0/nextjs-auth0属性

问题描述

搭建代码检查与测试的CI/CD工作流时,执行npm ci命令出现错误,报错信息为:

npm ERR! Cannot read property '@auth0/nextjs-auth0' of undefined

完整错误日志:

npm ci
shell: /usr/bin/bash -e {0}
npm ERR! Cannot read property '@auth0/nextjs-auth0' of undefined

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2023-05-14T13_03_54_383Z-debug.log
Error: Process completed with exit code 1.

使用的Workflow配置:

name: CICDNext

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  test:
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.os }}

    steps:
    - uses: actions/checkout@v2

    - name: Use Node.js
      uses: actions/setup-node@v2
      with:
        node-version: 14

    - name: Install dependencies
      run: npm ci
      working-directory: lms-app

    - name: Run Jest
      run: npm test
      working-directory: lms-app

    - name: Run Linting
      run: npm run lint
      working-directory: lms-app

项目package.json内容:

{
  "name": "lms-app",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev -p 3001",
    "build": "next build",
    "start": "next start",
    "lint": "next lint",
    "test": "jest --watch",
    "test:ci": "jest --ci"
  },
  "dependencies": {
    "@auth0/nextjs-auth0": "^2.6.0",
    "@headlessui/react": "^1.7.14",
    "@heroicons/react": "^2.0.17",
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^14.0.0",
    "@testing-library/user-event": "^14.4.3",
    "autoprefixer": "10.4.14",
    "axios": "^1.3.5",
    "babel-jest": "^29.5.0",
    "cors": "^2.8.5",
    "eslint": "8.37.0",
    "eslint-config-next": "13.3.0",
    "eslint-plugin-testing-library": "^5.11.0",
    "identity-obj-proxy": "^3.0.0",
    "jest": "^29.5.0",
    "jest-environment-jsdom": "^29.5.0",
    "jsonwebtoken": "^9.0.0",
    "next": "13.3.0",
    "postcss": "8.4.21",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-icons": "^4.8.0",
    "react-query": "^3.39.3",
    "tailwindcss": "3.3.1"
  }
}
解决方案

1. 提交package-lock.json到仓库

npm ci依赖package-lock.json实现精确依赖安装,如果仓库中没有该文件,会导致命令执行失败。

  • 本地执行npm install生成package-lock.json
  • 将该文件添加到Git仓库并推送

2. 升级Node.js版本

当前使用的Node.js 14版本过旧,项目依赖的next@13.3.0要求Node.js版本≥16.8,版本不兼容可能引发该错误。修改Workflow中的Node.js版本配置:

- name: Use Node.js
  uses: actions/setup-node@v2
  with:
    node-version: 18

3. 清理npm缓存

GitHub Actions的缓存可能导致依赖安装异常,可在安装依赖前添加缓存清理步骤:

- name: Clean npm cache
  run: npm cache clean --force
  working-directory: lms-app

4. 检查依赖兼容性

确认@auth0/nextjs-auth0@2.6.0与next@13.3.0的兼容性,可尝试调整该依赖版本:

  • 修改package.json中@auth0/nextjs-auth0的版本为^2.0.0或最新稳定版
  • 重新执行npm install生成新的package-lock.json后提交

内容的提问来源于stack exchange,提问作者Desmond Gilmour

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 03:32:10