今天在公司運(yùn)行著 react 程序, 在家里用自己的電腦
npx create-react-app 項(xiàng)目名
玩的不亦樂(lè)乎, 一道公司這個(gè)命令就不行了, 我特么吐了啊. 我很菜, 我重新運(yùn)行了三次這樣的項(xiàng)目, 同樣的命令還是不行, 差點(diǎn)崩潰.
然后想想會(huì)不會(huì)是我的react版本不一樣導(dǎo)致的問(wèn)題?把react-scripts
版本號(hào)4.0.3改成了4.0.1 ,重新npm i
加載依賴,最后可想而知,還是不行!!!然后發(fā)現(xiàn)會(huì)不會(huì)是項(xiàng)目命名的問(wèn)題?然后順藤摸瓜,發(fā)現(xiàn)了問(wèn)題的所在.
報(bào)錯(cuò):
./src/index.js 1:40
Module parse failed: Unexpected token (1:40)
File was processed with these loaders:
* ./node_modules/@pmmmwh/react-refresh-webpack-plugin/loader/index.js
* ./node_modules/react-scripts/node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
> $RefreshRuntime$ = require('C:/Users/de'l'l/Desktop/react/my-app/node_modules/react-refresh/runtime.js');
| $RefreshSetup$(module.id);
問(wèn)題
可以仔細(xì)看一下這段路徑有什么問(wèn)題?
我的 PC 名稱中有一個(gè)單引號(hào)字符de'l'l
, 就因?yàn)檫@個(gè)單引號(hào), 讓react版本4.0.1~4.0.3運(yùn)行崩潰, 為什么會(huì)崩潰這個(gè)我無(wú)法解釋, 這要react官方給出答案,不過(guò)很有趣.
解決辦法
只要該創(chuàng)建項(xiàng)目中的路徑不包含單引號(hào)的文件名即可, 可以放到更高級(jí)別的文件夾,就可正常運(yùn)行.