【发布时间】:2021-06-21 15:37:28
【问题描述】:
我在 Github 上配置了一个工作流,在运行 npm install 时出现此错误:
npm WARN saveError ENOENT: no such file or directory, open '/home/runner/work/project/project/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/home/runner/work/project/project/package.json'
npm WARN restaurateur No description
npm WARN restaurateur No repository field.
npm WARN restaurateur No README data
npm WARN restaurateur No license field.
据我了解,此错误意味着npm install 命令找不到package.json 文件,但是,我检查了package.json 在我的项目中可见。
我该如何解决这个问题?
这是我创建的 .yml 文件
name: project-folder
on:
push:
paths: project-folder**
branches: [main]
pull_request:
paths: project-folder/**
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 15.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
- name: Run the tests
run: npm test
- name: Build
run: npm run build
【问题讨论】:
-
确保您的
package.json和package-lock.json都已提交并推送到您的存储库。 -
它们都被推送到存储库。
-
package.json 文件是否在根存储库中? (类似问题:github.com/Azure/actions/issues/47)否则,我相信这个 npm install 操作可能会对您有所帮助:github.com/bahmutov/npm-install
-
您也可以使用 ls -la 命令运行一个步骤,以确保您位于所需的文件夹中。
标签: node.js json github npm github-actions