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

时间:2020-04-25 17:56:40

标签: reactjs create-react-app

创建React应用时显示图像中的错误。 这段时间一直工作正常,我所做的只是将mkdir和cd转到该目录。

这是错误的样子...

npx:在36.634s中安装了99 必须使用导入来加载ES模块:C:\ Users \ Neeraj \ AppData \ Roaming \ npm-cache_npx \ 5172 \ node_modules \ create-react-app \ node_modules \ is-promise \ index.js 不支持ES模块的require()。 C:\ Users \ Neeraj \ AppData \ Roaming \中的C:\ Users \ Neeraj \ AppData \ Roaming \ npm-cache_npx \ 5172 \ node_modules \ create-react-app \ node_modules \ is-promise \ index.js npm-cache_npx \ 5172 \ 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_npx \ 5172 \ node_modules \ create-react-app \ node_modules \ is-promise \ index.js重命名为.cjs,更改所需代码以使用import( ),或从C:\ Users \ Neeraj \ AppData \ Roaming \ npm-cache_npx \ 5172 \ node_modules \ create-react-app \ node_modules \ is-promise \ package.json中删除“ type”:“ module”。

3 个答案:

答案 0 :(得分:2)

这与is-promise库https://github.com/then/is-promise/issues/13有关。请不要降级节点版本。他们发布了新版本https://github.com/then/is-promise/releases/tag/2.2.1,可以解决此问题

答案 1 :(得分:1)

尝试将节点版本降级到12.11.1

$ npm install -g n $ n 12.12.0

答案 2 :(得分:1)

运行此命令:

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

或者,如果您只想创建react应用,则可以在等待修复的同时执行以下操作: 步骤1:yarn init -y

第2步:将其插入package.json

“决议”:{ “ is-promise”:“ 2.1.0”, “运行异步/承诺”:“ 2.1.0” }

第3步:添加--dev create-react-app

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