我遇到无法使用 npx 命令创建 React 应用程序的问题

I'm having a problem that can't create react app using npx command

我无法使用 npx create-react-app <projectname> 创建我的 React 项目。

控制台给出这个:

Must use import to load ES Module: C:\Users\user\AppData\Roaming\npm-cache\_npx36\node_modules\create-react-app\node_modules\is-promise\index.js // require() of ES modules is not supported. // require() of C:\Users\user\AppData\Roaming\npm-cache\_npx36\node_modules\create-react-app\node_modules\is-promise\index.js from C:\Users\user\AppData\Roaming\npm-cache\_npx36\node_modules\create-react-app\node_modules\run-async\index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules. // Instead rename C:\Users\user\AppData\Roaming\npm-cache\_npx36\node_modules\create-react-app\node_modules\is-promise\index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\Users\user\AppData\Roaming\npm-cache\_npx36\node_modules\create-react-app\node_modules\is-promise\package.json.

在安装 create-react-app 之前清理您的 npm 缓存。

npm cache clean --force

然后全局安装create-react-app

npm install -g create-react-app

然后您可以使用 create-react-app

创建您的 React 应用程序
create-react-app my-app

然后导航至 my-app 和 运行

npm start