npx create-react-app命令不起作用,而是返回ES模块错误



这是我运行的命令,试图创建一个React应用程序和由此产生的错误日志。我以前用命令$ npx create-react-app成功地运行过三次,但现在每次运行它时,它都不起作用,而是返回一个与ES模块相关的错误。我一直在尝试许多将React与Django集成的方法,但我不认为我在这样做的过程中编辑了任何会导致此错误的核心文件。我是React和Node.js的新手,所以任何建议都将不胜感激。

npx: installed 99 in 7.591s
Must use import to load ES Module: /Users/(username)/.npm/_npx/27993/lib/node_modules/create-react-app/node_modules/is-promise/index.js
require() of ES modules is not supported.
require() of /Users/(username)/.npm/_npx/27993/lib/node_modules/create-react-app/node_modules/is-promise/index.js from /Users/(username)/.npm/_npx/27993/lib/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 /Users/(username)/.npm/_npx/27993/lib/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 /Users/(username)/.npm/_npx/27993/lib/node_modules/create-react-app/node_modules/is-promise/package.json.```

这似乎是npm最近的一个问题。在过去的几个小时里,有一个问题悬而未决,似乎有人在处理它。我认为这与你的Django/Rect项目无关。

出票

在修复问题的同时:尝试安装节点版本12.12.0,如下所示,然后再次运行create-react应用程序。

nvm install 12.12.0
nvm use 12.12.0

这是节点的问题,您必须降级节点版本,或者您可以使用Yarn尝试以下操作:因此,很明显,问题来自npm,我们中没有人做错了什么,但我们仍然可以使用Yarn启动一个新的react项目,同时他们解决它,遵循以下步骤:

步骤1:纱线初始

步骤2:将其插入package.json

"决议":{"is promise":"2.1.0","run async/is promise":"2.1.0"}

步骤3:纱线添加-开发-创建反应应用

步骤4:纱线创建react应用程序/我的应用

相关内容

最新更新