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

Angular 5访问http://localhost:4200提示Cannot GET /问题求助

Fixing "Cannot GET /" in Angular 5 After ng serve Compiles Successfully

Hi Imran, sorry to hear you're stuck with this frustrating issue—let's walk through some targeted fixes to get your app up and running:

1. Check Node.js & Angular CLI Version Compatibility

Angular 5 has strict version requirements for Node.js (it officially supports Node 8.x to 10.x). If you're running a newer Node version (like 12+), it can cause silent runtime conflicts.

  • Run these commands in your terminal to verify versions:
    node -v
    ng -v
    

If your Node version is outside the supported range, use a version manager like nvm to switch to a compatible release (e.g., Node 10.24.1).

2. Validate .angular-cli.json Configuration

Angular 5 uses .angular-cli.json (not the newer angular.json) to define project settings. A misconfigured entry here can prevent the server from finding your app's entry point:

  • Open .angular-cli.json and confirm the apps section has these correct values:
    "apps": [
      {
        "root": "src",
        "outDir": "dist",
        "index": "index.html",
        "main": "main.ts",
        "polyfills": "polyfills.ts",
        "prefix": "app"
      }
    ]
    

Double-check that the index field points directly to src/index.html—a typo here will break the server's ability to load your app.

3. Clean Corrupted Cache & Reinstall Dependencies

Corrupted node modules or build cache are common culprits. Follow these steps to reset your project:

  1. Stop the ng serve process (press Ctrl+C in your terminal)
  2. Delete these items from your project directory:
    • node_modules folder
    • dist folder
    • package-lock.json file
  3. Reinstall dependencies:
    npm install
    
  4. Rebuild and serve the project again:
    ng serve
    

4. Test on a Different Port

Sometimes the default port 4200 is occupied by another application. Try serving your app on an alternate port:

ng serve --port 4201

Then visit http://localhost:4201 to see if the app loads correctly.

5. Check src/index.html for Issues

  • Ensure the src folder contains an index.html file (it should have been auto-created by ng new)
  • Verify the <base href="/"> tag is present in the <head> section of index.html—this tag tells Angular how to resolve route paths, and missing it can cause the "Cannot GET /" error.

Let me know if any of these steps resolve your problem!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 03:28:16