I am working on a react app using MSW. Everything was cool until I deployed my app to Github pages.
This is an error I get:
Uncaught (in promise) Error: [MSW] Failed to register a Service Worker for scope ('/') with script ('.js'): Service Worker script does not exist at the given path.
homepage in package.json:
/
I am working on a react app using MSW. Everything was cool until I deployed my app to Github pages.
This is an error I get:
Uncaught (in promise) Error: [MSW] Failed to register a Service Worker for scope ('https://myprofile.github.io/') with script ('https://myprofile.github.io/mockServiceWorker.js'): Service Worker script does not exist at the given path.
homepage in package.json:
http://myprofile.github.io/reponame/
Share Improve this question asked May 15, 2022 at 17:05 TeodorWolskiTeodorWolski 711 gold badge3 silver badges7 bronze badges1 Answer
Reset to default 2You need to only start
the worker
if the code is running in development environment.
Wherever you're starting the worker
(probably in index.js
file), add the following check:
if (process.env.NODE_ENV === "development") {
const { worker } = require("./mocks/browser");
worker.start();
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745317931a4622304.html
评论列表(0条)