在Plesk中部署Next.js应用启动失败:模块未找到及页面无限加载问题求助
Troubleshooting Next.js Deployment Issues on Plesk
Hey there, let's work through the problems you're facing with deploying your Next.js app on Plesk—since your build process works fine, we can focus on the startup and runtime issues.
1. Fixing "Cannot find module '../build/output/log'" Error
This error almost always ties to mismatched build output paths or incorrect startup commands. Here's how to resolve it:
- Verify your
package.jsonscripts:
Make sure your scripts look like this (adjust for Yarn if needed):
Next.js 12+ generates a{ "scripts": { "dev": "next dev", "build": "next build", "start": "next start -p 8080" // Use a port not blocked by Plesk } }.nextfolder (not an olderbuildfolder) afternext build, so thestartcommand doesn't need custom paths—it automatically uses the.nextoutput. - Check Plesk application settings:
In your Plesk Node.js app configuration:- Set Application root to your project's root directory (where
package.jsonlives). - Leave Startup file empty, or set it to
node_modules/next/dist/bin/next(this tells Plesk to use Next's built-in server). - Ensure the Command field uses
start -p [your-port](match the port in yourstartscript).
- Set Application root to your project's root directory (where
2. Resolving Infinite Page Load / No Response
If your app starts but the page hangs, these are the most likely fixes:
- Port & Reverse Proxy Setup:
- Pick a unique port (e.g., 8080, avoid 3000 if it's used by other services) and confirm it's allowed in your server's firewall (Plesk has a firewall tool under "Security" to open the port).
- Configure Plesk's reverse proxy to forward your domain traffic to the port your Next.js app uses. Go to your domain's "Apache & Nginx Settings" and add a custom Nginx rule like:
location / { proxy_pass http://localhost:8080; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; }
- Check Runtime Logs:
In Plesk, navigate to your app's "Logs" tab—this will show you if there are hidden errors (like failed API routes or missing environment variables) that aren't showing up in the browser. - Avoid Dev Mode in Production:
Never usenpm run devto start your production app—it's for development only. Always runnpm run buildfirst, thennpm run start.
3. Fixing "Error build module not found"
This usually happens when dependencies are missing or build artifacts are incomplete:
- Reinstall Dependencies:
In Plesk's terminal, navigate to your project root and run:
Therm -rf node_modules package-lock.json .next npm install --production=false--production=falseflag ensures all development dependencies (which Next.js needs for building) are installed. - Check Ignore Files:
Make sure your.gitignoreor.npmignoreisn't accidentally excluding critical folders likepages/,components/, orpublic/—these are required for Next.js to build and run correctly. - Match Node.js Versions:
Ensure the Node.js version in Plesk matches what you used locally for development. You can switch versions in Plesk's Node.js app settings under "Node.js version".
内容的提问来源于stack exchange,提问作者Luca Schönherr
相关产品推荐
相关产品推荐

