I'm talking about the problem i face during deploying my first Modular project called contact manager (SPA) on my GitHub profile, and then how i solved it.
First of all, if you don't know anything about what is modular project, or SPA (single page application), its not something totally different type, it runs same as that simple 3 files (index.html, style.css & main.js) web app, but now it has many files, like if i show you in visuals,
/simple web application
|---- index.html
|---- main.js
|---- style.css
/Modular (Single Page Application)
├── index.html
├── /js/
│   ├── app.js
│   ├── router.js
│   └── views/
│       ├── HomeView.js
│       ├── CompletedView.js
│       └── StatsView.js
└── /css/
    └── style.css
So what actually happened, i built and practiced my first Single Application Project, and after making it working perfectly, after polishing it a bit, i think i should push it to my GitHub, as my first step in building SPAs, but what happens when i try pushing it,
If you're a dev who use GitHub, you might know that GitHub doesn't allow pushing whole project folder at once, it allows only files not folders, especially if you're pushing your project manually on GitHub through browser drag & drop.
So i need to create a copy of that project, and i flattened that whole copy, remove all folders & edit all the imports,
from this --->  '/src/js/router.js' to that ---> '/router.js'..
Then i started creating a repo on my GitHub for that project, i setup it carefully with nice name and description, & i pushed my project file by file, then after making it live, when i opened that live site, i got panicked,
What happened,?.. while testing that flatten version on local server, it was working perfectly, but i don't understand what happened on gitHub, why GitHub's behavior is something different for this project than my previous simple three file projects i pushed, i know that it has many files, & i was expecting that kind of issue,
I immediately go to chat gpt, i asked,
"Is modular Javascript project, doesn't work as normal one file Javascript web projects on github?"
It's response was:
"When you create a modular JavaScript project (like an SPA with ES modules), your files are split across multiple JS modules:
// main.js
import { showQuotes } from './utils/quote.js';
Here the browser needs to load each imported file separately, respecting the module system.
But GitHub Pages (and normal static hosting) just serves plain files — it doesn’t “build” or bundle your project like npm/Vite does.
So if your folder structure or import paths aren’t correct (especially case sensitivity or relative paths), or if your imports use local paths, it can break after deployment." 
It suggested me some common reasons like
"1. Missing type="module"
Wrong import paths (case or folder)
GitHub Pages URLs are case-sensitive.
So import "./Utils.js" ≠ utils.js.Root-relative imports fail
Don’t use /src/..., always use relative paths like ./src/....Files not uploaded correctly
If your folder structure changes (e.g. src/ or modules/), make sure the exact structure is uploaded.Index file not at the root
GitHub Pages serves from / by default, so index.html must be in the root of your repository (not inside src)."
then i explain everything to it, what i did like
"In local server it was working perfectly... right know, its impossible for me to do upload whole folder at once even if i try, GitHub drag & drop only allow files not folders...
I made a copy of my project, & edited it, for GitHub, i removed all folders, & reconnected modules file to file,
then i tested it locally, it was fully ready for github, but now, don't know why GitHub behaving this way"
my code doesn't have any problems like the ones you showed as reasons, then it suggested me something that changes everything for me, he suggested me to do one thing..
It asked me to update each import in each file in that project on github, what it wanted me to do is,
I should update my imports, from '/app.js' to './app.js', 
or from '/style.css' to './style.css'
In easy words, it wanted me to add '.' before every import in that project, and when i try running my project on github after doing all of these things.
Boom... i successfully deployed my first modular project. I built and made it run live on github, the issue i was facing, was gone now.
I learned & understand that deploying modular JS projects is slightly different from regular scripts. Always check your paths, use a local server, and remember that GitHub Pages hosts your files at a specific URL structure.
This small issue taught me something bigger — every error or failure hides a new concept waiting to be understood.
I used to get nervous when something broke, but now I see it as part of learning. 


    
Top comments (0)