使用 create-react-app 创建 React 应用程序时出错

Error while creating a react app using create-react-app

创建 React 应用程序时出现图像中的错误。 它一直都在正常工作,我所做的只是 mkdir 和 cd 到那个目录。

这是错误的样子...

npx: 在 36.634 秒内安装 99 必须使用 import 加载 ES Module: C:\Users\Neeraj\AppData\Roaming\npm-cache_npx72\node_modules\create-react-app\node_modules\is-promise\index.js 不支持 ES 模块的 require()。 require() of C:\Users\Neeraj\AppData\Roaming\npm-cache_npx72\node_modules\create-react-app\node_modules\is-promise\index.js from C:\Users\Neeraj\AppData\Roaming\npm-cache_npx72\node_modules\create-react-app\node_modules\run-async\index.js 是ES模块文件 因为它是一个 .js 文件,其最近的父 package.json 包含 "type": "module" ,它将该包范围内的所有 .js 文件定义为 ES 模块。 而是将 C:\Users\Neeraj\AppData\Roaming\npm-cache_npx72\node_modules\create-react-app\node_modules\is-promise\index.js 重命名为以 .cjs 结尾,将需要的代码更改为使用 import(),或者从 C:\Users\Neeraj\AppData\Roaming\npm-cache_npx72\node_modules\create-react-app\node_modules\is-promise\package.[ 中删除 "type": "module" =31=].

尝试将节点版本降级到 12.11.1

$ npm install -g n $ n 12.12.0

运行 这个命令:

npm install is-promise@2.1.0 --save --save-exact

或者,如果您只想创建 React 应用程序,您可以在等待修复时执行此操作: 第 1 步: yarn init -y

第 2 步:将此插入 package.json

"resolutions":{ "is-promise": "2.1.0", "run-async/is-promise": "2.1.0" }

第 3 步:yarn add --dev create-react-app

第 4 步:yarn create-react-app ../my-app

这与 is-promise 库有关 https://github.com/then/is-promise/issues/13. Please don't downgrade the node version. They have released new version https://github.com/then/is-promise/releases/tag/2.2.1,它将解决此问题