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

使用Jump.js实现平滑滚动遇GitHub 404错误求助(NPM新手)

Fixing Jump.js 404 Error on GitHub Pages (Works Locally with Live Server)

Hey there! Let's get your smooth scroll working on GitHub Pages—since it runs fine locally with Live Server, the issue almost always ties back to how your files are structured or deployed. Here's what you need to do:

1. Stop relying on node_modules for GitHub Pages

Chances are, your node_modules folder isn't being uploaded to GitHub (most projects have a .gitignore file that excludes it by default, which is actually good practice!). That's why the server can't find ./node_modules/jump.js/dist/jump.module.js—the folder doesn't exist on GitHub at all.

Fix options:

  • Copy the Jump.js file to your public assets:
    Grab jump.module.js from node_modules/jump.js/dist/ and paste it into a dedicated folder in your project like assets/js/. Then update your import to:
    import jump from './assets/js/jump.module.js';
    
  • Use a CDN instead:
    Skip local files entirely and import directly from a CDN. Replace your existing import with this in your script:
    import jump from 'https://cdn.skypack.dev/jump.js';
    
    This way, you don't need to worry about hosting the file yourself.

2. Double-check relative file paths

GitHub Pages serves your site from a root that includes your repository name (e.g., https://your-username.github.io/your-repo-name/). Make sure your file paths are relative to this root. For example:

  • If your script is in js/main.js and Jump.js is in the same js/ folder, the import should be ./jump.module.js.
  • If Jump.js is in your project's root directory, use ./jump.module.js.

3. Confirm your GitHub Pages deployment settings

Head to your repository's Settings > Pages and verify:

  • You're deploying the correct branch (usually main or gh-pages).
  • The deployment source points to the right directory (most static sites use the root / folder).

Since you're new to NPM, a quick tip: node_modules is meant for local development dependencies, so you never want to commit it to GitHub. Using CDNs or copying necessary files to your public assets folder is the standard approach for static hosting like GitHub Pages.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.12 03:43:28