javascript - MSW: Failed to register a ServiceWorker for scope with script The script has an unsupported MIME type ('tex

I am working on a react app using MSW. Everything was cool until I deployed my app to Github pages.Thi

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 badges
Add a ment  | 

1 Answer 1

Reset to default 2

You 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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信