Laravel与VueJS页面加载异常求助:页面无限循环且/js/landing.js请求长期Pending
Hey there, let's tackle this tricky issue step by step. I've dealt with similar WSL + Laravel + Vue problems before, so here are some practical troubleshooting directions and fixes to try:
1. Fix WSL File System Permission & Location Issues
WSL and Windows file system interactions often cause permission or file watch glitches.
- If your Laravel project is stored in a Windows directory (like
/mnt/c/Users/...), move it to WSL's native file system (e.g.,~/projects/your-app). Then re-runnpm install,npm run watch, andphp artisan serve—this often resolves file access bottlenecks. - If you don't want to move the project, fix permissions in your project root:
This ensures Laravel has proper read/write access to critical directories.sudo chmod -R 755 storage bootstrap/cache
2. Verify npm Watch Compilation Status
Sometimes npm run watch fails silently, leaving an incomplete or missing landing.js file.
- Check the terminal running
npm run watchfor errors (like ESLint violations, missing dependencies). Fix any compilation issues first. - Run
npm run devmanually to force a full compile, then check ifpublic/js/landing.jsexists and has a reasonable file size (not empty or tiny).
3. Double-Check Laravel Mix Configuration
Incorrect Mix settings can lead to wrong asset paths or missing output files.
- Open
webpack.mix.jsand confirm your Vue compilation config looks correct:mix.js('resources/js/landing.js', 'public/js') .vue(); - Ensure there's no custom public path override that's sending compiled assets to the wrong directory.
4. Rule Out Browser Cache & Proxy Interference
Browser cache or proxy tools can block asset requests and cause pending statuses.
- Access the page in your browser's incognito mode to bypass cached resources.
- Close any proxy tools (like Fiddler or Charles) running on your Windows machine, then refresh the page.
5. Fix WSL Port Forwarding & Network Glitches
The default php artisan serve setup on WSL sometimes has port forwarding issues.
- Get your WSL IP by running
hostname -Iin the WSL terminal, then start the server with that IP:
Access the page using this IP (e.g.,php artisan serve --host=YOUR_WSL_IP --port=8000http://192.168.x.x:8000) instead oflocalhost. - Temporarily disable Windows Firewall to check if it's blocking the 8000 port.
6. Check for Vue Route Infinite Loops
The page infinite loop might stem from Vue routing logic, not just asset loading.
- Open
resources/js/landing.jsand inspect your route guards (likebeforeEach). Look for logic that causes endless redirects, such as:router.beforeEach((to, from, next) => { // Bad example: no exit condition, forces constant redirect next('/login'); }); - Ensure your route guards have clear conditions to stop the loop.
内容的提问来源于stack exchange,提问作者HalloSouf

