升级ngx-config依赖后Angular 5出现运行时错误:Endpoint unreachable
Hey there, let's work through this runtime error you're hitting after updating ngx-config—since ng serve compiles without a hitch, the problem is definitely tied to how the library tries to fetch your config once the app is running.
Common Fixes to Try
Double-check your config endpoint URL
First up: verify the endpoint you've set in ngx-config's initialization. After an upgrade, the library might have changed how it resolves URLs (like requiring an absolute path instead of a relative one, or vice versa). Pop open yourapp.module.ts(or wherever you set upNgxConfigModule) and look at theendpointvalue in theforRoot()setup. Try accessing that URL directly in your browser to confirm it's reachable and returns valid config data.Check for CORS restrictions
If your config endpoint is on a different domain, CORS could be blocking the request. Even if this worked before, the updated library might send slightly different headers that trigger a block. Open your browser's DevTools (F12), go to the Network tab, and look for the config request—if it fails with a CORS error, you'll need to update your backend to allow requests from your app's domain, or set up a proxy in your Angular dev environment.Review ngx-config's breaking changes
Version upgrades often come with breaking tweaks. Take a look at the release notes for the ngx-config version you moved to—they might have modified how config is loaded (like switching fromHttptoHttpClient, or adding new required config options). For example, some newer versions require explicitly enablinguseHttpor adjusting the request method from GET to something else.Inspect the Network tab for failed request details
This is a quick way to get concrete clues. Open DevTools > Network tab, filter by XHR/fetch requests, then reload your app. You'll see the exact request ngx-config is making. Check the status code:- 404 means your URL is incorrect
- 500 points to a backend issue
- 403 indicates permission problems
This will tell you exactly why the endpoint is unreachable.
Validate your local config file (if using one)
If you're loading a local file likeconfig.jsoninsrc/assets/, make sure it's still in the right spot and hasn't been corrupted. The upgraded library might have stricter JSON parsing rules—even a missing comma or extra quote could cause it to fail silently and throw this generic error.
Quick test: You can temporarily hardcode your config using the
configoption inNgxConfigModule.forRoot()to skip the endpoint fetch. If the error disappears, you know the problem is definitely with the endpoint setup.
内容的提问来源于stack exchange,提问作者rmlarsen

