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

部署Express.js+React.js项目到Heroku时遇模块缺失错误求助

Fixing "Cannot find module './school'" on Heroku Deployment

Hey there, let's get your app up and running on Heroku quickly—your error log tells us exactly what's going wrong here.

The Root Cause

Looking at your logs, the critical line that's breaking your deployment is:

Error: Cannot find module './school'

This almost always happens for one of two simple reasons:

  1. Case sensitivity mismatch: Local development (especially on Windows) uses a case-insensitive file system, so require('./school') will find School.js or SCHOOL.js just fine. But Heroku runs on Linux, which is strictly case-sensitive—so the filename has to match exactly what's in your require statement.
  2. Missing file in Git: The school.js file exists on your local machine, but you never added or committed it to Git, so it doesn't get pushed to Heroku during deployment.

Step-by-Step Fixes

1. Verify File Existence & Case Matching

  • Navigate to your controllers directory and check the exact filename of your school controller. Is it school.js, School.js, or something else?
  • Open /controllers/index.js (the file throwing the error) and look at the first require statement—it should look like:
    const schoolController = require('./school');
    
    Make sure the path here matches your actual filename exactly (including uppercase/lowercase letters). If your file is School.js, update the require to require('./School'), or rename the file to school.js to match the existing require statement.

2. Ensure the File is Committed to Git

  • Run git status in your project root. Look for any untracked files—if school.js (or your renamed file) is listed, it means it hasn't been added to Git yet.
  • Add and commit the file:
    git add controllers/school.js  # Replace with your actual file path
    git commit -m "Add missing school controller file"
    

3. Re-deploy to Heroku

  • Push your updated code to Heroku:
    git push heroku main  # Use "master" instead of "main" if that's your default branch
    
  • Once deployment finishes, check the logs again with heroku logs --tail to confirm the module error is gone. Then visit your app at xxxxx.herokuapp.com—it should no longer show the "Application error" page.

Extra Tips for Heroku Deployment

  • Always double-check case sensitivity for all file paths when deploying to Linux-based platforms like Heroku—this is a super common gotcha!
  • Make sure all backend dependencies are listed in your package.json (Heroku installs only what's in this file).
  • For your PostgreSQL/Sequelize setup later, ensure your app is using Heroku's DATABASE_URL environment variable instead of local credentials.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.09 13:12:47