jenkins打包报错 - 实践

报错信息

Done in 14s using pnpm v10.16.1
> jg-inms-application-app@develop develop
> vite build --mode develop
[36mvite v5.4.21 [32mbuilding for develop...[36m[39m
<script src="./config/basic.js"> in "/index.html" can't be bundled without type="module" attribute
  transforming...
  [unplugin-vue-components] component "IndexRange"(/data/.jenkins/workspace/jg-inms-application-web/src/components/MyDateTime/indexRange.vue) has naming conflicts with other components, ignored.
  [unplugin-vue-components] component "Index copy"(/data/.jenkins/workspace/jg-inms-application-web/src/components/MyTerminal/index copy.vue) has naming conflicts with other components, ignored.
  [32m[39m 634 modules transformed.
  [31mx[39m Build failed in 5.34s
  [31merror during build:
  [31m[vite:load-fallback] Could not load /data/.jenkins/workspace/jg-inms-application-web/src/components/MyUpload/index.vue (imported by src/plugins/components.js): ENOENT: no such file or directory, open '/data/.jenkins/workspace/jg-inms-application-web/src/components/MyUpload/index.vue'[31m
  at async open (node:internal/fs/promises:639:25)
  at async Object.readFile (node:internal/fs/promises:1246:14)
  at async Object.load (file:///data/.jenkins/workspace/jg-inms-application-web/node_modules/.pnpm/vite@5.4.21_@types+node@24.9.2_sass@1.65.1_terser@5.44.0/node_modules/vite/dist/node/chunks/dep-BK3b2jBa.js:65357:25)
  at async PluginDriver.hookFirstAndGetPlugin (file:///data/.jenkins/workspace/jg-inms-application-web/node_modules/.pnpm/rollup@4.52.5/node_modules/rollup/dist/es/shared/node-entry.js:22308:28)
  at async file:///data/.jenkins/workspace/jg-inms-application-web/node_modules/.pnpm/rollup@4.52.5/node_modules/rollup/dist/es/shared/node-entry.js:21308:33
  at async Queue.work (file:///data/.jenkins/workspace/jg-inms-application-web/node_modules/.pnpm/rollup@4.52.5/node_modules/rollup/dist/es/shared/node-entry.js:22536:32)[39m
  find:/data/.jenkins/workspace/jg-inms-application-web/dist/: 没有那个文件或目录
  找出路径==>
  开始压缩
  /usr/bin/jenkins-web-package.sh:58:cd: /data/.jenkins/workspace/jg-inms-application-web/dist: 没有那个文件或目录
  zip warning: name not matched: develop
  zip error: Nothing to do! (try: zip -r develop.zip . -i develop)
  [Pipeline] }
  [Pipeline] // stage
  [Pipeline] stage
  [Pipeline] { (远程部署)
  [Pipeline] sshPublisher
  SSH: Connecting from host [dev-centos]
  SSH: Connecting with configuration [192.168.100.90] ...
  SSH: Creating session: username [root], hostname [192.168.100.90], port [22]
  SSH: Connecting session ...
  SSH: Connected
  SSH: Opening SFTP channel ...
  SSH: SFTP channel open
  SSH: Connecting SFTP channel ...
  SSH: Connected
  SSH: cd [/]
  SSH: OK
  SSH: Opening exec channel ...
  SSH: EXEC: channel open
  SSH: EXEC: STDOUT/STDERR from command [bash /usr/bin/jenkins-web-deploy.sh jg-inms-application-web develop jg-inms-application-web] ...
  SSH: EXEC: connected
  开始解压缩
  unzip:  cannot find or open /data/java-project/jg-inms-application-web/develop.zip, /data/java-project/jg-inms-application-web/develop.zip.zip or /data/java-project/jg-inms-application-web/develop.zip.ZIP.
  mv: 无法获取'/usr/local/nginx/html/web/develop/jg-inms-application-web/develop/*' 的文件状态(stat): 没有那个文件或目录
  SSH: EXEC: completed after 200 ms
  SSH: Disconnecting configuration [192.168.100.90] ...
  ERROR: Exception when publishing, exception message [Exec exit status not zero. Status [1]]
  [Pipeline] }
  [Pipeline] // stage
  [Pipeline] }
  [Pipeline] // node
  [Pipeline] End of Pipeline
  Finished: UNSTABLE
  

原因: /components/MyUpload/index.vue文件引入大小写问题;
vue3文件引入大小写检查与修复


看到Jenkins部署Vue3项目失败了。从日志来看,问题链条比较清晰:Vite构建失败导致没有生成dist目录,进而导致后续的压缩和部署步骤失败。下面我帮你梳理一下问题和解决方案。

为了让你能快速把握核心疑问和应对方案,我先用一个表格来汇总主要的错误点、原因和解决方向:

错误阶段关键错误信息/现象可能原因/解决方案
Vite构建Could not load .../MyUpload/index.vue: ENOENT1. 文件缺失:确认MyUpload/index.vue文件是否存在。
2. 大小写敏感:检查文件名/路径大小写是否正确。
Vite构建component "IndexRange" ... has naming conflicts组件命名冲突:检查方案中是否有重复注册的同名组件。
后续步骤没有那个文件或目录, Nothing to do!构建失败连锁反应:Vite构建失败未生成dist目录,导致后续步骤(压缩、部署)失败。此问题会在Vite构建成功后自动解决。

详细分析与解决方案

1. 解决Vite构建失败(核心)

构建失败是当前所有问题的根源,主要需要解决两个错误。

  • 修复档案路径错误
    日志显示无法加载 /src/components/MyUpload/index.vue 文件。Linux系统对文件路径大小写敏感,这和Windows/macOS不同。请按以下步骤排查:

    • 确认文件存在:在Jenkins工作空间中,检查文件 /src/components/MyUpload/index.vue 是否存在。
    • 检查路径和文件名大小写:确认路径中每一个字母的大小写都与代码中的import语句完全匹配。例如,myuploadMyuploadMyUpload 会被视为不同的文件。
  • 处理组件命名冲突
    日志中出现了组件命名冲突的警告。这即使可能不会直接导致构建失败,但最好予以应对。

    • 检查 src/plugins/components.js 以及其他你注册了全局组件的地方,确保没有重复注册相同名称的组件。
    • 重点关注冲突的组件:IndexRangeIndex copy
2. 修复HTML中的脚本引用

日志中有一行提示:<script src="./config/basic.js"> in "/index.html" can't be bundled without type="module" attribute

  • 对于在 index.html 中直接引用的、不需要Vite处理的传统全局脚本,可以<script>标签上添加 type="module" 属性,或者更常见的做法是添加 rel="modulepreload"
3. 优化Jenkins流程与安装

通过在解决完构建障碍后,能够考虑优化Jenkins流程,避免类似问题。

  • 构建失败应提前终止继续执行无意义的后续步骤。就是:目前的流程是即使Vite构建失败了,依然试图执行后续的压缩和部署步骤。你可以在Jenkins Pipeline中调整,当构建阶段失败时,直接退出整个Pipeline,标记构建为失败,而不

总结与行动步骤

  1. 首要任务:登录Jenkins服务器,进入本次构建的工作空间目录,仔细检查并修复 /src/components/MyUpload/index.vue记录路径和大小写问题。这是最可能导致构建失败的环节。
  2. 次要清理:解决 index.html 中的脚本引用问题和组件命名冲突警告。
  3. 流程优化构建失败,则让Jenkins Pipeline直接终止,避免执行后续步骤。就是:在Vite构建步骤后,增加逻辑判断。若

希望这些步骤能帮助你快速定位并解决问题。如果排查了文件路径问题后依然失败,可以告诉我更多的上下文信息,例如MyUpload组件相关的导入代码,我们再一起分析。

posted on 2025-11-29 10:25  ljbguanli  阅读(0)  评论(0)    收藏  举报