问题描述
我之前使用'npx create-react-app my-app'命令创建了一个react项目,并且'my-app'文件夹包含以下文件和文件夹:
I created a react project with the 'npx create-react-app my-app' command before and the 'my-app' folder contains this files and folders:
my-app
├── README.md
├── node_modules
├── package.json
├── .gitignore
├── public
│ ├── favicon.ico
│ ├── index.html
│ └── manifest.json
└── src
├── App.css
├── App.js
├── App.test.js
├── index.css
├── index.js
├── logo.svg
└── serviceWorker.js
└── setupTests.js
但是现在当我使用相同的命令创建一个react项目时, my-app文件夹仅包含 node_modules文件夹和 package.json yarn.lock文件。
But now when I create a react project with the same command, the 'my-app' folder contains only 'node_modules' folder and 'package.json' 'yarn.lock' files.
my-app
├── node_modules
├── yarn.lock
└── package.json
我认为可能是因为使用了过时的create-react-app版本,然后要解决此问题,我执行了以下步骤:
I thought probably for using an outdated version of create-react-app, then to fix this, I did the following steps:
- 通过运行
npm rm -g create-react-app
- 通过运行
npm install -g create-react-app
- Removing the old version of CRA by running
npm rm -g create-react-app
- Installing the new version globally by running
npm install -g create-react-app
$ b $在全球安装新版本b
但是我的问题仍然存在。我想到的最后一件事是将node.js从v10升级到v12.16.3,但没有任何改变。
But my issue still existed. The last thing that came to my mind was upgrading node.js from v10 to v12.16.3, but nothing didn't change.
推荐答案
发生此问题是因为不再支持 create-react-app
的全局安装。
要解决此问题,请分别运行以下命令:
This problem occurred because there is global installs of create-react-app
are no longer supported.For solving this problem, run these command respectively:
npm uninstall -g create-react-app
然后以这种方式安装 create-react-app
npm install create-react-app
然后创建您的应用程序
npx create-react-app my-app
这篇关于为什么使用“ npx create-react-app”命令创建项目时,除了“ node_modules”和“ package.json”之外,再没有文件和文件夹了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!