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

求助:JavaScript在本地localhost运行正常,部署至GitHub Pages或Vercel后失效,仅index.html与cadastro.html异常

Troubleshooting Missing JS Files on GitHub Pages & Vercel

Hey there! Let's break down why your JavaScript files work perfectly locally but go missing on deployed platforms like GitHub Pages and Vercel—especially since your home.html runs without issues. Here are the most common fixes to try:

1. Fix Relative Path Mismatches

This is the #1 culprit for deployment path issues. Local servers and hosted platforms handle base URLs differently:

  • On your local server, localhost:XXXX/ acts as your project root, so paths like /js/script.js work because they point directly to your project's js folder.
  • But on GitHub Pages, your site lives at https://marincor.github.io/Bx-Bank/—so an absolute path like /js/script.js would try to load from https://marincor.github.io/js/script.js (which doesn't exist), instead of your repo's actual js folder.

Fix:
Compare the <script> tags in index.html/cadastro.html with the working ones in home.html. If the broken pages use absolute paths starting with /, switch to relative paths:

  • Use ./js/your-script.js (anchors to the current file's directory)
  • Or just js/your-script.js (works if the HTML file is in the root, same as your js folder)

2. Check for Case Sensitivity Issues

Local systems like Windows don't care about uppercase/lowercase in file names, but GitHub Pages and Vercel run on Linux, which is strictly case-sensitive.

  • If your folder is named js but your script tag says <script src="JS/script.js"></script>, it'll work locally but fail once deployed.

Fix:
Double-check the spelling and case of your js folder and file names in both your HTML code and GitHub repo. Make sure they match exactly (e.g., js/main.js not Js/Main.js).

3. Verify File Presence & Git Ignore Settings

Even though home.html works, it's worth confirming:

  • The JS files referenced in index.html/cadastro.html actually exist in your GitHub repo's js folder (no typos in file names).
  • Your .gitignore file isn't accidentally excluding any of these JS files or the entire js folder.

Fix:
Browse your GitHub repo directly to confirm the files are present. If they're missing, check your local .gitignore and commit/push the missing files to the repo.

4. Clear Browser & Deployment Cache

Sometimes old cached files can make it look like your JS is missing, even if it's deployed correctly.

  • Browser cache: Press Ctrl+Shift+R (Chrome) to force a hard refresh, or open DevTools > Network tab > check "Disable cache" and reload the page.
  • Deployment cache: Both GitHub Pages and Vercel sometimes cache old builds. For Vercel, trigger a manual redeploy; for GitHub Pages, push a tiny change (like updating a comment) to force a rebuild.

5. Check Deployment Logs

If none of the above works, look at the deployment logs for clues:

  • GitHub Pages: Go to your repo's Settings > Pages > check the build status at the top for errors.
  • Vercel: Log into your dashboard, find the bx-bank project, and review the deployment logs for any "file not found" errors related to your JS files.

Once you fix the path or case issues, your JS files should show up in DevTools' Sources tab on both platforms!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.29 22:13:11