Npm 安装在 github 操作中失败

我尝试创建一个使用 vue 和 vue-cli-plugin-electron-builder 构建我的电子应用程序的 github 操作,但我无法通过 npm 安装依赖项

我的文件夹树是这样的:

|   .gitignore
|   babel.config.js
|   LICENSE
|   package-lock.json
|   package.json
|   README.md
|   vue.config.js
|   yarn.lock
|
+---public
|       favicon.ico
|       index.html
|       test.jpg
|
\---src
    |   App.vue
    |   background.js
    |   main.js
    |   preload.js
    |
    +---assets
    |       ...
    |
    \---components
            ...

当我运行 CI 时,我发现了一个错误

  npm ci
  shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
npm ERR! The `npm ci` command can only install with an existing package-lock.json or
npm ERR! npm-shrinkwrap.json with lockfileVersion >= 1. Run an install with npm@5 or
npm ERR! later to generate a package-lock.json file,then try again.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\npm\cache\_logs\2021-08-01T04_59_20_385Z-debug.log
Error: Process completed with exit code 1.

这是我的空白.yml:

# This is a basic workflow to help you get started with actions

name: CI

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

  # Allows you to run this workflow manually from the actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    name: Build
    runs-on: windows-latest
    steps:
    - name: Install Node.js,NPM and Yarn
      uses: actions/setup-node@v1
      with:
          node-version: 16
    - name: Install Dependencies
      run: |
            npm ci
    - name: Electron Build
      run: |
            npm run electron:build --windows nsis --x64 --ia32

我尝试使用关键字“npm install failed in github action”在 bing 上进行搜索,但我发现没有任何帮助。 另外,我尝试使用“npm install”代替“npm ci”,但它显示了相同的错误消息,即找不到 package.json 'npm install' 的错误信息如下:

Run npm install
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path D:\a\example\example/package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory,open 'D:\a\example\example\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!     C:\npm\cache\_logs\2021-08-01T05_12_56_060Z-debug.log
Error: Process completed with exit code 1.

我该如何解决?

英语不是我的母语;请原谅打字错误。

PZY97649 回答:Npm 安装在 github 操作中失败

您没有检查代码并直接运行 NPM CI。 下面的一段代码应该为你做这项工作

name: CI
on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    name: Build
    runs-on: windows-latest
    steps:
    - name: Checkout Code
      uses: actions/checkout@v2
    - name: Install Node.js,NPM and Yarn
      uses: actions/setup-node@v1
      with:
          node-version: 16
    - name: Install Dependencies
      run: |
            npm ci
    - name: Electron Build
      run: |
            npm run electron:build --windows nsis --x64 --ia32

本文链接:https://www.f2er.com/3228.html

大家都在问