[์—๋Ÿฌ ์ผ์ง€] MSW - Failed to register the Service Worker: Failed to register a ServiceWorker for scope ...

nemoยท2022๋…„ 6์›” 15์ผ
0

์—๋Ÿฌ ์ผ์ง€

๋ชฉ๋ก ๋ณด๊ธฐ
17/26

๐Ÿšซ [MSW] Failed to register the Service Worker: Failed to register a ServiceWorker for scope ('http://localhost:3001/') with script ('http://localhost:3001/mockServiceWorker.js'): The script has an unsupported MIME type ('text/html'). at getWorkerInstance (getWorkerInstance.ts:85:1) at async startWorkerInstance (createStartHandler.ts:30:1)

MSW๋ผ๋Š” ๋ชจํ‚น ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ๋ชจ์˜ ์„œ๋ฒ„๋ฅผ ๊ตฌํ˜„ํ•˜๋˜ ์ค‘์— worker๋ฅผ ์‹คํ–‰ํ•˜๋ ค๊ณ  ํ•˜๋ฉด ์œ„์™€ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค.

(index.tsx)

if (process.env.NODE_ENV === "development") {
  const { worker } = require("./mocks/browser");
  worker.start();
}

ํ•ด๋‹น ์—๋Ÿฌ๋Š” ํ”„๋กœ์ ํŠธ ๋‚ด์— mockServiceWorker.js ํŒŒ์ผ์ด ์—†๊ธฐ ๋•Œ๋ฌธ์— ๋ฐœ์ƒํ•œ ์—๋Ÿฌ์ด๋‹ค.
์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜์—ฌ public ํด๋”์— mockServiceWorker.js๋ฅผ ์ƒ์„ฑํ•ด์ฃผ์ž.

npx msw init public/

yarn npm msw init public/


public ํด๋”๋ฅผ ํ™•์ธํ•ด๋ณด๋ฉด ํ•ด๋‹น ํŒŒ์ผ์ด ์ƒ์„ฑ๋˜์–ด ์žˆ์Œ.

์ฝ˜์†”์—์„œ๋„ MSW๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์‹คํ–‰๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

0๊ฐœ์˜ ๋Œ“๊ธ€