Quiero incluir Mock Service Worker en mi proyecto React con compatibilidad con TypeScript, pero tan pronto como ejecuto el comando npm install msw --save-dev, mi terminal me muestra estos mensajes de error:
PS F:\Programming\React Practices\ReactPizza\my-app> npm install msw --save-dev npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: msw@0.41.0 npm ERR! Found: typescript@4.7.2 npm ERR! node_modules/typescript npm ERR! peer typescript@">= 2.7" from fork-ts-checker-webpack-plugin@6.5.2 npm ERR! node_modules/fork-ts-checker-webpack-plugin npm ERR! fork-ts-checker-webpack-plugin@"^6.5.0" from react-dev-utils@12.0.1 npm ERR! node_modules/react-dev-utils npm ERR! react-dev-utils@"^12.0.1" from react-scripts@5.0.1 npm ERR! node_modules/react-scripts npm ERR! react-scripts@"5.0.1" from the root project npm ERR! peerOptional typescript@"^3.2.1 || ^4" from react-scripts@5.0.1 npm ERR! node_modules/react-scripts npm ERR! react-scripts@"5.0.1" from the root project npm ERR! 2 more (tsutils, the root project) npm ERR! npm ERR! Could not resolve dependency: npm ERR! peerOptional typescript@">= 4.2.x <= 4.6.x" from msw@0.41.0 npm ERR! node_modules/msw npm ERR! dev msw@"*" from the root project npm ERR! npm ERR! Conflicting peer dependency: typescript@4.6.4 npm ERR! node_modules/typescript npm ERR! peerOptional typescript@">= 4.2.x <= 4.6.x" from msw@0.41.0 npm ERR! node_modules/msw npm ERR! dev msw@"*" from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force, or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution. npm ERR! npm ERR! See C:\Users\Win10\AppData\Local\npm-cache\eresolve-report.txt for a full report. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\Win10\AppData\Local\npm-cache\_logs\2022-05-27T17_17_28_323Z-debug.logNo sé cuál es el problema, y cómo solucionarlo. Mi mini proyecto funciona con create-react-app. Quiero decir que el proyecto se inició con esto:
npx create-react-app my-app --template typescriptCuando no utilizo Typescript con npx create-react-app, todo va bien.
Puede verificar fácilmente esos mensajes de error en GitHub: https://github.com/AlexKor-5/ReactPizzaApp_Ts/tree/5849bb4cb928550dcb4bfd66ecb8b7bf0757fb9f al intentar instalar MSW.