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

Vuepress基于Travis CI构建时提示找不到package.json文件该如何处理?

报错说明

执行Travis CI构建Vuepress项目时触发以下报错,核心原因为指定路径下找不到package.json文件:

error Couldn't find a package.json file in "/home/travis/build/comter1/document"
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The command "yarn document:build" exited with 1.
$ yarn cname
yarn run v1.22.4
error Couldn't find a package.json file in "/home/travis/build/comter1/document"
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The command "yarn cname" exited with 1.
cache.2
store build cache
Done. Your build exited with 1
排查步骤
  • 确认package.json在仓库中的实际存放路径,核对路径是否和Travis执行命令的路径/home/travis/build/comter1/document匹配
  • 核对目录名称大小写,Travis运行在Linux环境下大小写敏感,若本地目录名大小写和配置中写的不一致,也会出现路径识别错误
  • 检查仓库的.gitignore规则,确认package.json没有被加入忽略列表,已正常推送到远程仓库
  • 检查.travis.yml配置,确认执行构建命令前是否错误切换了工作目录,或者没有切换到package.json所在的目录
  • 确认Travis CI拉取的代码分支正确,是包含package.json提交的目标分支
解决方案

根据package.json的存放位置调整Travis配置即可:

  1. 如果package.json存放在仓库根目录:
    修改.travis.yml的构建命令,不要错误切换到document目录,直接在根目录执行命令即可,也可以显式指定工作目录:
script:
  - yarn --cwd ./ document:build
  - yarn --cwd ./ cname
  1. 如果package.json存放在document子目录:
    先切换到对应目录再执行构建命令:
script:
  - cd document
  - yarn document:build
  - yarn cname
  1. 如果是monorepo多包架构:
    按包管理工具的工作区规则指定对应子包路径执行命令即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.02 03:06:03