执行 create-react-app 以创建新的 React 应用程序时出错

时间:2021-01-22 06:57:04

标签: reactjs create-react-app

之前我在全局安装了 create-react-app,并且多次使用 npx create-react-app appName 命令来创建新的 React 应用程序。一切正常,但突然间我在使用相同的命令创建新应用时遇到了问题。

现有的 react 应用程序运行良好,我可以导航到这些目录并运行 npm start,应用程序将开始运行/工作顺利,只有 create-react-app 无法正常工作。

NPM 版本:6.14.11

节点版本:v10.15.3

React 脚本版本(在现有应用的 package.json 中找到):

"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.0",

我已经浏览了 this stack-overflow question 并尝试了答案中给出的一些建议

我尝试清除缓存:npm cache clean --force

我更新了 npm 版本 npm install npm@latest -g

我曾尝试使用这 3 种方法:

  1. npx create-react-app test100

  2. 首先创建目录 test100,然后从该目录 npx create-react-app .

  3. 正如 here 提到的,如果 create-react-app 是全局安装的,那么不需要使用 npm/npx/yarn。所以尝试了这个create-react-app test100

但是无论我尝试什么,我都会遇到如下相同的错误,它表示无法将某些网站图标文件从 CRA 模板复制到应用程序的公共目录,然后它会终止整个操作并删除 package.json 文件。

请让我知道如何解决这个问题,因为我长期被困在这个问题上,任何帮助将不胜感激。

注意:我在 windows 机器上工作,并且在管理员模式下打开了 VScode。

请检查我在 VScode powershell 控制台中遇到的以下错误:

PS C:\Vikrant Local\react> npx create-react-app test100

Creating a new React app in C:\Vikrant Local\react\test100.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...


> core-js@2.6.12 postinstall C:\Vikrant Local\react\test100\node_modules\babel-runtime\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"


> core-js@3.8.3 postinstall C:\Vikrant Local\react\test100\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"


> core-js-pure@3.8.3 postinstall C:\Vikrant Local\react\test100\node_modules\core-js-pure
> node -e "try{require('./postinstall')}catch(e){}"


> ejs@2.7.4 postinstall C:\Vikrant Local\react\test100\node_modules\ejs
> node ./postinstall.js

+ cra-template@1.1.1
+ react@17.0.1
+ react-scripts@4.0.1
+ react-dom@17.0.1
added 1903 packages from 722 contributors and audited 1906 packages in 95.612s

126 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

fs.js:114
    throw err;
    ^

Error: UNKNOWN: unknown error, copyfile 'C:\Vikrant Local\react\test100\node_modules\cra-template\template\public\favicon.ico' 
-> 'C:\Vikrant Local\react\test100\public\favicon.ico'
    at Object.copyFileSync (fs.js:1723:3)
    at copyFile (C:\Vikrant Local\react\test100\node_modules\fs-extra\lib\copy-sync\copy-sync.js:67:6)
    at onFile (C:\Vikrant Local\react\test100\node_modules\fs-extra\lib\copy-sync\copy-sync.js:53:25)
    at getStats (C:\Vikrant Local\react\test100\node_modules\fs-extra\lib\copy-sync\copy-sync.js:48:44)
    at startCopy (C:\Vikrant Local\react\test100\node_modules\fs-extra\lib\copy-sync\copy-sync.js:38:10)
    at copyDirItem (C:\Vikrant Local\react\test100\node_modules\fs-extra\lib\copy-sync\copy-sync.js:122:10)
    at fs.readdirSync.forEach.item (C:\Vikrant Local\react\test100\node_modules\fs-extra\lib\copy-sync\copy-sync.js:115:39)    
    at Array.forEach (<anonymous>)
    at copyDir (C:\Vikrant Local\react\test100\node_modules\fs-extra\lib\copy-sync\copy-sync.js:115:23)
    at mkDirAndCopy (C:\Vikrant Local\react\test100\node_modules\fs-extra\lib\copy-sync\copy-sync.js:110:3)

Aborting installation.
  node  has failed.

Deleting generated file... node_modules
Deleting generated file... package.json
Done.

1 个答案:

答案 0 :(得分:0)

如何使用 yarn 创建您的 CRA 模板。

运行npm i -g yarn

然后yarn create react-app my-app

相关问题