Angular 7 PWA部署后出现Manifest获取失败(404)错误求解决方案
Hey, I’ve dealt with this exact frustrating 404 issue when deploying Angular 7 PWAs before—let’s break down the most common fixes that resolved it for me and other developers:
Verify your
angular.jsonasset configuration
The #1 culprit is usually thatmanifest.jsonisn’t being copied to your production build folder. Double-check yourangular.jsonunder thebuild > options > assetsarray to ensure it explicitly includessrc/manifest.json:"assets": [ "src/favicon.ico", "src/assets", "src/manifest.json" // Critical line—don’t omit this! ],After updating, rebuild with
ng build --prodand check yourdistfolder—you should seemanifest.jsonthere. If not, recheck your file path (make sure it’s not insrc/assets/manifest.jsonunless you reference it that way).Fix the
index.htmlmanifest link
A typo or incorrect path in yourindex.html’s manifest link will also trigger a 404. Confirm thehrefmatches your deployment path:- If your app is deployed at the root domain (e.g.,
https://example.com/), use:<link rel="manifest" href="manifest.json"> - If deployed to a subpath (e.g.,
https://example.com/my-app/), use the full relative path:<link rel="manifest" href="/my-app/manifest.json">
Double-check for typos (likemanifests.jsoninstead ofmanifest.json—we’ve all been there!).
- If your app is deployed at the root domain (e.g.,
Check server configuration
Sometimes the issue isn’t with Angular, but your web server blocking or misrouting the manifest request:- Ensure your server (NGINX, Apache, etc.) is serving files from the correct
distdirectory. - Add the correct MIME type for manifests—some servers return 404 for unrecognized file types. For NGINX, add this to your config:
types { application/manifest+json json; } - Avoid rewrite rules that redirect all requests to
index.html(common in SPA setups)—make suremanifest.jsonis excluded from these rules.
- Ensure your server (NGINX, Apache, etc.) is serving files from the correct
Validate
ngsw-config.jsonpaths
Your PWA’s service worker config might be pointing to the wrong manifest path. Openngsw-config.jsonand confirm themanifestentry matches your deployment URL:"manifest": "/manifest.json"If you’re using a subpath, update it to something like
"/my-app/manifest.json".Quick debug trick
Open your browser’s DevTools > Network tab, refresh the page, and look for themanifest.jsonrequest. Check the "Request URL" to see exactly where the browser is trying to fetch it—this will immediately tell you if the path is wrong or the file isn’t being served.
内容的提问来源于stack exchange,提问作者Karthikeyan Vellingiri

