Hello and thanks in advance for any help. I got a service-worker up and running with my react-app, it runs perfectly on local builds and when deployed from Azure pipelines as well. Problem is in production, which is deployed via Cloudflare, the service worker throws this error in console and cannot figure out why: "Uncaught (in promise) bad-precaching-response: bad-precaching-response :: [{"url":"https://example.com/static/media/getFetch.xxxxxxxxxxxxx.cjs","status":404}]"
Now the said file "getFetc.xxxx.....cjs" seems to be there under static/media/ build files
Any suggestions would be welcome!
reason being "getFetc.xxxx.....cjs" this is a static file so you have to mention a rule in your web.config file ,so that this particular file is processed.
Add following line in your web.config file :
<staticContent>
<mimeMap fileExtension=".cjs" mimeType="text/javascript" />
</staticContent>
Hope this will help you..!
Ok, problem solved, and in our case it was actually an error in the server not serving the file whne requested, so apparently nothing was wrong client-side
Related
I am working on a React app that's running on AWS Amplify. My React app is using the react-router-dom library to route to different components. After running amplify publish in the CLI, at the root of the app (obktraining.com) everything is fine in the browser, I can also route to other components in the app just fine as well. But when I refresh my browser while I am on a route (obktraining.com/menu), I get an Access Denied error message.
I have found other posts about similar issues regarding rewrites and redirects in Amplify, but the solutions given do not work for me.
Here is an image of the error:
My Amplify app rewrites & redirects :
Again, the error only displays when I refresh on a route (obktraining.com/menu or obktraining.com/drinks) not on obktraining.com. Is the issue being caused by the react-router-dom library or is it an issue with Amplify settings? I am not sure where to go from here.
I have been facing the same error since days.The error is being caused by the amplify settings. The solution is simple,
Edit your Rewrites and redirects by adding a new rule.
source address = </^[^.]+$|.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map|json)$)([^.]+$)/>
target address = /index.html
status = 200 (Rewrite)
Country code can be left blank
Save and try refreshing your app again. It should probably work.
use this for reference: https://docs.aws.amazon.com/amplify/latest/userguide/redirects.html#redirects-for-single-page-web-apps-spa
Then you can just put in (as Dhruv Godambe posted above)
</^((?!.(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$).)*$/>
as the Source address and
/index.html as your target address
You can navigate to 'rewrites and redirects' in your app from AWS Amplify console and click on edit and select open text editor, and add this piece of code in your array(if present) else put the array braces around it.
{
"source": "</^[^.]+$|\\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$)([^.]+$)/>",
"target": "/index.html",
"status": "200",
"condition": null
}
Reference: https://docs.aws.amazon.com/amplify/latest/userguide/redirects.html#redirects-for-single-page-web-apps-spa
Reference:
https://docs.aws.amazon.com/amplify/latest/userguide/manual-deploys.html
I have faced the same problem.
I was using Manual Zip File (Compressed) download (wrong).
Here is how to deploy manually correctely:
Run this command
npm run build
Now a build folder will be created.
2. Compress the content of this folder
Not the content of the whole project.
You chnage directory to the build folder and Compress the content in side.
3. Upload that compressed file Inside the build directory
Now this should work just fine.
:)
The correct rule should be like this:
Source address: </^[^.]+$|\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$)([^.]+$)/>
Target address: /index.html
Status: 200
I was getting the an Access Denied error message too. The error went away when I followed the documentation described in the answer above, but then I got the white screen problem described above too.
Reviewing the steps I noticed the auto-complete for the "Destination Address" listed in the "Rewrites and redirects" settings was /. When I tried using / as the "Destination Address" instead of /index.html I no longer got the white screen and got the expected page content.
Sharing what I found in case this helps others who are seeing a white screen after fixing the error with the rewrite rule described in the answers above. (Note as of Nov 2022 the "Rewrites and redirects" setting page uses the wording "Target Address" instead of "Destination Address".)
I have faced the same problem. I was zipping build folder, but not the contents within the zip folder.
Here is how I fixed it:
Run build command
npm run build
Now a build folder will be created inside your project directory.
Open build folder.
Compress the contents of build folder, and not build folder.
Now upload this new zip created from sub files and folders from build folder.
App will run fine on AWS Amplify.
I got the same error,
I zipped the build folder first then uploaded it and got that error,
but when I just uploaded the folder without zipping it, it worked fine !! weird!!
in my application I used the port 8080
I am in the process of deploying a dynamic, React.js app to Heroku and wanted to test it out by using 'heroku local' to see if it works before pushing it to Heroku. Everything seemed to be working fine with the server - my database console.log message logs to the terminal signifying everything is going well - but when I try to access the website which is on localhost:5000, I get an error message of 'Cannot GET /' and the console prints a message saying , 'Failed to load resource: the server responded with a status of 404 (Not Found)'. My React.js files are all within the build folder which in conjunction with all of the other files, were pushed to git and commited, but for some reason my files are not showing up. I would greatly appreciate if someone could help me determine what went wrong. Sorry if my question is a little vague; please let me know if I can clarify something in better detail as I am fairly new to programming.
I've added a proxy to one of my package.json files to help with url routing; possibly this could be causing the issue?
Also, if it helps at all, a photo of my folders within Visual Studio code are listed below:
I have angular 8 front end application in production and its Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
This issue is happening only in production build that too not always , able reproduce only sometimes.
main-es2015.fcc7123d15fd9c113b00.js:1
vendor-es2015.d8d7d81cc2b06ece8c91.js:1
How do i fix it.?
Are you using serviceWorker?
If so you have to add inside angular.json "serviceWorker": true for the configuration that you are using.
I would like to share my experience with the same issue I was facing in the organization where I'm working.
I had an Angular 9 application and when I deployed to Stage environment, I got three errors in my console which showed as "module not loaded due to Mime type". This was working fine in all other environment and after much struggle, it was found that the files under the website were not having access. E.g. When you deploy an Angular application, you will get index.html file and many other js files. The website had permission issues. The site was hosted in the Rackspace and the FireWall was not configured to have access to the files right under the website.
Once the below access was provided, the app started working.
/assets*
/*.css
/*.js
/*.ico
/*.html
The only difference I see with your problem is that you have mentioned it is working sometimes.
There is another post Blocked because of a disallowed MIME type (“text/html”) : Angular 8 deployed on tomcat 9.0.30 fails to serve the assets try the solution based on base reference as those js files are not served/loaded
I hope this might help someone.
I've found this to be a very useful tutorial so far, probably one of the best step by step guides ever created for programming as EVERY SINGLE STEP is seen committed via GitHub:
http://docs.angularjs.org/tutorial/the_end
I hit a brick wall towards the middle and I can't host a json object on a Microsoft IIS server I have provided by GoDaddy. I have to edit my web.config file because Microsoft apparently thought it was a great idea to throw a 404 on the URL of a pure JSON object:
http://cinicraft.com/angular/phones/phones.json
So that's a valid URL according to my FTP browser, but yeah I get a 404. Microsoft is brilliant in using the "not found" error exception with a file that exists.
And so I can't really go any further with the tutorial, I've decided to try running the completed version Google has available on GitHub, but I have no idea on how to run this:
۩/partials/
۞/phone-list.html
۞/phone-detail.html
۩/js/
۞/jquery.js
۞/controllers.js
۞/app.js
۞/angular.min.js
۞/bootstrap.min.js
۩/angular
۞/angular-route.js
۩/test
۩/phones
۩/fonts
/index.html
If I just open index.html straight from my finder on Chrome I only see a blank page, how does one run this AngularJS app?
Is node.js required?
Please look at the url https://github.com/angular/angular-phonecat and Prerequisites
Go to applicationhost.config file in your IIS config folder and add the following where similar mime types are defined
<mimeMap fileExtension=".json" mimeType="application/json" />
If still not allowed go to <requestFiltering> section and add the following
<add fileExtension=".json" allowed="true" />
Has anyone meet the same problem as the following error message shows when calling bluetoothDeive.createBond() method with android 4.4 api?
java.lang.SecurityException: Need BLUETOOTH PRIVILEGED permission
Note: BLUETOOTH_ADMIN permission is already included in AndroidManifest file.
Got the exact error message.
Took me an hour to realize that the bluetooth on the phone is not enabled. After turning it on, it works as expected.
You can't use this permission if your app is a third party app (non-system app). To learn more, see Android API: BLUETOOTH_PRIVILEGED
I run on this error, and only I can say, you need to install your app as a system privileged app, to go to system folder and try to copy app to the app folder or priv_app folder. On my Android platform, when I made folder inside priv_app folder for my app and copied my apk to it and restarted Android, everything worked OK.
I my case I added in manifest all this permissions at the beginning, but it worked only after this step above.
Try this:
1) remove "android.permission.BLUETOOTH_PRIVILEGED" from your permissions.
2) remove "android.permission.BLUETOOTH".
3) add "android.permission.BLUETOOTH_ADMIN" and just that.
The reference says that is the only permission needed.https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#createBond()
EDIT: if you already included "bluetooth_admin", maybe its a platform problem.They may have not supported that functionality earlier. Maybe you should target a higher min-sdk-platform , Im using Android 20 as the minimum (but never tried that function).
try this in your manifest
<user-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
notice the user not uses-permission on the first line. Until I switched that, For some reason I kept getting
java.lang.SecurityException: Need BLUETOOTH_ADMIN permission