what is the use of manifest.json in react.js - reactjs

My firebase hosted page is rendering a blank page. The console says there are some problem in manifest.json. Can anyone please help in figuring it out.
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
The errors in console are

I was able to debug and solve the issue, actually there was some misconfiguration in the firebase installation.
Deleted firebase.json
run firebase init
Set the deploy target as from https://firebase.google.com/docs/cli/targets
firebase target:apply TYPE TARGET_NAME RESOURCE_IDENTIFIER
Where the parameters are:
TYPE — the relevant Firebase resource type
For Firebase Hosting sites, use hosting.
TARGET_NAME — a unique name for the Hosting site that you're deploying to
RESOURCE_IDENTIFIER — the SITE_ID for the Hosting site as listed in your Firebase project
For example, if you've created two sites (myapp-blog and myapp-app) in your Firebase project, you could apply a unique TARGET_NAME (blog and app, respectively) to each site by running the following commands:
firebase target:apply hosting blog myapp-blog
firebase target:apply hosting app myapp-app
Then created deploy target in the array of firebase.json
{
"hosting": [ {
"target": "blog", // "blog" is the applied TARGET_NAME for the Hosting site "myapp-blog"
"public": "blog/dist", // contents of this folder are deployed to the site "myapp-blog"
// ...
},
{
"target": "app", // "app" is the applied TARGET_NAME for the Hosting site "myapp-app"
"public": "app/dist", // contents of this folder are deployed to the site "myapp-app"
// ...
"rewrites": [...] // You can define specific Hosting configurations for each site
}
]
}
{
"storage": [ {
"target": "main", // "main" is the applied TARGET_NAME for the group of Cloud Storage buckets
"rules": "storage.main.rules" // the file that contains the shared security rules
}
]
}
The I used,
npm run build
6. Then run,
firebase deploy

Related

Error: Assertion failed: resolving hosting target of a site with no site name or target name -> Deploying change in Firebase Hosting to Live site

{
"database": {
"rules": "database.rules.json"
},
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"hosting": [
{
"public": "dist/nur",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
},
{
"target": "nur",
"public": "dist/nur",
"ignore": [
"**/.*"
],
"headers": [
{
"source": "*.[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].+(css|js)",
"headers": [
{
"key": "Cache-Control",
"value": "public,max-age=31536000,immutable"
}
]
},
{
"source": "/#(ngsw-worker.js|ngsw.json)",
"headers": [
{
"key": "Cache-Control",
"value": "no-cache"
}
]
}
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
],
"storage": {
"rules": "storage.rules"
}
}
Tried firebase deploy command through Firebase to deploy the changes.
Deploying to 'nur-beta'...
i deploying database, storage, firestore, hosting
i database: checking rules syntax...
database: rules syntax for database nur-beta-default-rtdb is valid
i firebase.storage: checking storage.rules for compilation errors...
firebase.storage: rules file storage.rules compiled successfully
i firestore: reading indexes from firestore.indexes.json...
i cloud.firestore: checking firestore.rules for compilation errors...
cloud.firestore: rules file firestore.rules compiled successfully
After all resources deployement it gives assertion failed message.
Error: Assertion failed: resolving hosting target of a site with no site name or target name. This should have caused an error earlier. May I know what I'm missing while deploying the changes to already LIVE web-site hosted under Firebase Hosting.
There is no problem with your JSON file.
For deployment to firebase hosting first of all you have to build your project then you push your project to firebase hosting
command to build the project and deploy it to firebase
For angular use the ng build command in the terminal of your project location.
after building run the firebase deploy command
See the Magic
I ran into this issue recently and what worked for me was adding the target name in firebase.json:
"hosting": [
{
"target": "TARGET_NAME",
....
}
]
Please note that this is a hotfix. I have not fully investigated the root cause, but it helped me to deploy the app when I needed it.
I had the same issue, I fixed it by running
firebase init and reinitializing the project.

How to make AWS Amplify access my React App's public directory

I deployed my React App on AWS Amplify. The problem is it doesn't access the sources in Public folder(e.g. images, models). I heard I can add rules to Rewrite and Redirect on AWS Amplify, but I have no idea how to make the rule.
This is my folder layout:
The rules in AWS Amplify:
How do I make the rules? Could someone help me out?
Sorry, this is sort of a 'shotgun' answer, but I suspect one of these should move you forward.
This issue may have more to do with your build tools than Amplify.
In my vite spa, I put my favicon.svg, logo.svg in my /src directory. The only thing in my public dir is an image referenced in an email html - and for that it seems I hardcoded a fully qualified path.
I have an old CRA SPA, and I see things like this:
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
And you may need to expose files via manifest.json
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
Rewrites/redirects probably aren't the reason images aren't working. But if everything appears to work as long as you nav from your homepage, but breaks if you reload or deep link - that's where the rewrite rules will help.
The doc is on this page. From the doc:
Redirects for single page web apps (SPA)
Most SPA frameworks support HTML5 history.pushState() to change
browser location without triggering a server request. This works for
users who begin their journey from the root (or /index.html), but
fails for users who navigate directly to any other page. Using regular
expressions, the following example sets up a 200 rewrite for all files
to index.html, except for the specific file extensions specified in
the regular expression.
Source address:
</^[^.]+$|\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|woff2|ttf|map|json)$)([^.]+$)/>
Target address:
/index.html
Type:
200 (Rewrite)

Cannot register service worker on react serverless

I am trying to register a service worker to make a react application PWA, when deployed on GitHub pages.
The error I am getting is:
No matching service worker detected. You may need to reload the page, or check that the scope of the service worker for the current page encloses the scope and start URL from the manifest.
This is the manifest.json:
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": "https://[github-username].github.io/",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
In packages.json:
"homepage": "https://[githubid].github.io/[repository]",
Both service-worker.js and register-serviceWorker.js are located in src folder.
I have tried to build it locally and serve it with npm serve, and the browser identifies the service worker.
My belief is that the scope and start url are not ok configured in manifest.json.
I have added the following to manifest.json:
"start_url": "https://[gitHubId].github.io/",
"scope": "/",
It now works.
I was getting the same issue in dev. env. even tho i run the build with serve package .
The solution was to export NODE_ENV=production as environment variable.
or we can simply remove production condition in service worker registration file.
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator)

Deploy React App and Express API on Vercel

I want to deploy a project that includes a React App as frontend (client/) and an Express API backend (api/) on vercel. I'm able to deploy the api but how can I deploy also the client?
My project structure:
-api/
-package.json
-index.js
-client/
-package.json
-public/...
-src/...
-vercel.json
My current vercel.json:
{
"version": 2,
"builds": [
{
"src": "./api/index.js",
"use": "#vercel/node"
},
// that is what I tried but it's not working:
{
"src": "./client/package.json",
"use": "#vercel/static-build"
}
// End of the non-functional code
],
"routes": [
{
"src": "api/.*",
"dest": "api/index.js"
},
// that is what I tried but it's not working:
{
"src": "client/build/static/.*",
"dest": "static/.*"
},
{
"src": "client/build/index.html",
"dest": "index.html"
}
// End of the non-functional code
]
}

Firebase react.js app deployed - blank page

I am using Firebase for the first time and I deployed a react app I know to be working and have hosted on github pages. I followed the instructions provided by Firebase docs and deployed the app to their website. On loading the website I am greeted with a blank page.
the link: https://monsterpwa.web.app/
the firebase.json file:
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
The previous posts on here are all bout the public sections being changed to build. Other then that I could not find anyone else with a similar question.
The console logs and error that there is an unexpected token '<' in line one column 1, but I also cannot see that.
The manifest file:
{
"short_name": "Monster App",
"name": "Monster App D&D Spells and Items",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "/public/media/800x800.png",
"type": "image/png",
"sizes": "800x800"
}
],
"start_url": "./index.html",
"display": "standalone",
"background_color": "#2d4059;",
"theme_color": "#2d4059",
"orientation": "portrait-primary"
}
build
Build
--> Media -- > *empty*
--> static -- > css / js --> each contains two files. main.7bf83f0f & the map version & main.3267ab84 and the map version.
asset-manifest.json
favicon.ico
index.html
manifest.json
service-worker.js
worker.js
Kind regards,
Snow
The issue is that you've configured your app to look for assets in a /MonsterPWA directory but that doesn't appear to exist.
For example, your index.html file has
<script type="text/javascript" src="/MonsterPWA/static/js/main.3267ab84.js"></script>
but the file is actually available at /static/js/main.3267ab84.js.
Your rewrite rule is catching all non-existent file requests and returning index.html, hence the warnings about <.
Check your homepage configuration in package.json and / or your PUBLIC_URL environment variable.
If you check the JavaScript console of your browser it shows there's a problem loading the CSS.
Resource interpreted as Stylesheet but transferred with MIME type text/html: "https://monsterpwa.web.app/MonsterPWA/static/css/main.7bf83f0f.css".
Uncaught SyntaxError: Unexpected token '<'
From looking at the Network tab, we can see that it is loading this URL https://monsterpwa.web.app/MonsterPWA/static/css/main.7bf83f0f.css, but that is returning HTML (due to your rewrite rule).
Make sure that your CSS is generated to build/MonsterPWA/static/css/main.7bf83f0f.css, since that's where Firebase Hosting looks for it.
Edit: a quick check shows that the CSS actually exists at https://monsterpwa.web.app/static/css/main.7bf83f0f.css so at build/static/css/main.7bf83f0f.css.
Do the following:
run the command: npm run build
check firebase.json file to ensure it says "public":"build".. if not make the change
run the command: firebase deploy
Go grab a coffee!

Resources