无法通过CRA PWA的灯塔审核

 收藏

I am trying to build a PWA with CRA and ran into some issues. However, even though I have registered the user (serviceWorker.register() in index.js) and can store the files in cache storage and run it offline, I still cannot pass the audit and I get (I've built my web app already, so it's running in production mode):

1.start_url does not respond with a 200 when offline Unable to fetch start URL via service worker.

2.Current page does not respond with a 200 when offline

3.Does not register a service worker that controls page and start_url

Which in my opinion is caused by wrong start_url.

I have a manifest.json and index.html in public folder and serviceWorker.js, index.js inside the src folder (inside public). and I get service-worker.js and manifest.json in the build folder after I build the app.

I've tried changing the start_url to "." , "index.html", "/" and some other options, but it did not change anything, still the same error.

编辑

我也得到这个

Network tab in Chrome

Console in Chrome

Error in this line in serviceWorker.js:

提取(swUrl)

Seems like service-worker.js, manifest.json are not precached. This is weird, because from my understanding it should be precached automiatically. What is the solution here ?

回复