第一天学习React,使用Create React App创建项目时遇到了一些问题,请记录下来。
问题说明webstorm使用npx创建- react-app my-app创建项目
npm start期间发生错误:
webpack版本问题webpack-dev-server版本问题new-appgit: (主控) ) ) ) ) ) ) ) ) )。 npmstartnew-app @0.1.0start react-scriptsstarttheremightbeaproblemwitheprojectdependencytree.itislikelynotabugincration y.the react-scriptspackageprovidedbycreatereactapprequiresadependency 3360 ' web pack-dev-dev-1.1 ' don ' trytoinstoinstall tomatically.However,adifferentversionofwebpack-dev-serverwasdetectedhigherupinthetree :/users/Roger Qian/node manuallyinstallingincompatibleversionsisknowntocausehard-to-debug issues.ifyouwouldprefertoignorethischeck, add skip _ preflight _ check=true toan.envfileinyourproject.thatwillpermanentlydisablethissagebutyoumightencounterourothect tryfollowingthestepsbelowintheexactorder :1.delete包- lock.JSON (not包. JSON! ) and/or yarn.lockinyourprojectfolder.2.delete node _ modulesinyourprojectfolder.3.remove ' web pack-dev-server ordevdepeper older.4.runNPMinstallorYarn,dependingonthepackagemanageryouse.in most cases,thisshouldbeenoughtofixtheproblem.ifthinaghed thereareafewotherthingsyoucantry :5.ifyousednpm, 安装yarn (http://yarn pkg.com/andrepeattheabovestepswithitinstead.thismayhelpbecausenpmhasknownissueswithpackagehoistingwhichmaygetresolvedinfutureversionsiongutureverersionononionionion Roger Qian/node _ modules/web pack-dev-serverisoutsideyourprojectdirectory.for example, youmighthaveaccidentallyinstalledsomethinginyourhomefolder.7.tryrunningnpmlswebpack-dev-serverinyourprojectfolder.thh expectedreact-scripts )安装的web pack-dev-server.ifnothingelsehelps, add skip _ preflight _ check=true toan.envfileinyourproject.thatwouldpermanentlydisablethispreflightcheckincaseyouwanttto 在出现webpack错误之前,没有记录上述webpack-dev-server版本问题
最终解决方案把光盘放在全球目录上,比如我的
Users/rogerqian/node_modules
卸载web包和web包-CLI和web包-dev-server
npmunwebpacknpmunwebpack-clinpmunwebpack-dev-server将根据以前在终端上报告的错误提示安装相应的版本。 我的React是17.0.2,对应的版本如下
npmiwebpack @4. 44.2 npmiwebpack-clinpmiwebpack-dev-server @3. 11.1然后可以通过npx create-react-app成功启动