-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: Service worker has an unsupported MIME type ('text/html') #10658
Comments
Have you found any workarounds to solve this issue? @ebenezerdon |
Did you also remove the process.env.NODE_ENV === 'production' to get it to work on localhost? |
Yes You need to remove and save it as a comment near by temporarily |
Facing the same issue @ebenezerdon any fixes or work arounds found yet ? |
workaround - deploy a production build to a local static server:
|
I ended up fixing it by updating serviceWorker scripts with the newest version of CRA. Just generate a new project and copy the relevant files over. |
@robinjhuang - that didn't work for me (i created the app with the pwa template today, so i'm assuming it's the latest version as well). or do you mean the latest version of the core template, and not the pwa? |
@eliranmal What error are you seeing regarding import statements? I never had import statement errors. That seems like a different issue. My understanding of the MIME type error is that indicates that the service worker did not register correctly. I just ran |
well, in typescript all the code is always pre-processed by the typescript compiler (even files inside the public directory, if they are this is not the case in vanilla javascript, where copying the file would suffer broken dependencies (since no dependency resolution can done by the module builder in such code; what is the meaning of by the way, the mime type error happens before the service worker has a chance to register (or even load its module code) - it is thrown because the server is not set up to serve this path/uri pattern, or due security restrictions in the client. |
Sorry, can you explain your set up? You're not using typescript I'm assuming. Also, here are my file locations. They're not in public/ |
my setup is an unejected i'm not sure anymore that the problem can be resolved by manually copying the file. i believe that's the job of the workbox plugin (that eventually receives this file's path), but for some reason it's blocked in development (i presume due known issues with the devserver). can't help much more 🤷 |
Given this issue was encountered on Windows and seems to match the symptoms we experienced on Windows I'm wondering if this PR would be relevant: #11640 |
Has anybody figured this out? I have created a fresh project using And it's not working for localhost. Note: I have already removed this condition: Also I have tried the solution suggested here: https://stackoverflow.com/questions/49566059/service-worker-registration-error-unsupported-mime-type-text-html But it didn't work |
The following steps worked out for me and resolved the issue.
let newSw = await navigator.serviceWorker.register( |
When working on localhost, you need to do this:
const WorkboxWebpackPlugin = require("workbox-webpack-plugin");
const path = require("path");
module.exports = function override(webpackConfig, env) {
//do stuff with the webpack config...
const isEnvDevelopment = env === "development";
if (isEnvDevelopment) {
const newConfig = {
...webpackConfig,
plugins: [
...webpackConfig.plugins,
new WorkboxWebpackPlugin.InjectManifest({
swSrc: path.resolve(__dirname, "src/service-worker.js"),
dontCacheBustURLsMatching: /\.[0-9a-f]{8}\./,
exclude: [/\.map$/, /asset-manifest\.json$/, /LICENSE/],
maximumFileSizeToCacheInBytes: 5 * 1024 * 1024,
}),
],
};
return newConfig;
} else {
return webpackConfig;
}
}
That's it... now, the service worker that is at |
Hello i use antd pro. was setting up pushy notifications.
|
Describe the bug
Using the create-react-app-typescript-pwa template to generate a progressive web app returns the following error when `serviceWorker.register() is called:
checkValidServiceWorker()
function in./src/serviceWorkerRegistration.ts
:Did you try recovering your dependencies?
Yes
Please paste the output of
npm --version
and/oryarn --version
to confirm.-->
7.6.1
Which terms did you search for in User Guide?
PWA, TypeScript, Workbox, Service worker
Environment
current version of create-react-app: 4.0.3
System:
OS: Windows 10 10.0.17763
Steps to reproduce
npx create-react-app my-app --template cra-template-pwa-typescript
serviceWorker.unregister()
toserviceWorker.register()
Expected behavior
Actual behavior
Service worker not registered
The text was updated successfully, but these errors were encountered: