简体   繁体   English

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

[英]npx create-react-app command does not work, returns ES module error instead

Here is the command that I ran to try to create a React app and the resulting error log.这是我运行以尝试创建 React 应用程序和生成的错误日志的命令。 I have been able to successfully run it three times before with the command $ npx create-react-app , but now every time that I run it, it does not work and instead returns an error related to ES modules.我之前可以使用$ npx create-react-app命令成功运行它 3 次,但现在每次运行它时,它都不起作用,而是返回与 ES 模块相关的错误。 I have been experimenting with many ways to integrate React with Django, but I don't think that I edited any core files in doing so that would have caused this error.我一直在尝试将 React 与 Django 集成的多种方法,但我认为我没有编辑任何会导致此错误的核心文件。 I am completely new to React and Node.js so any advice would be greatly appreciated.我对 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.```

This seems to be a recent problem with npm.这似乎是 npm 最近出现的问题。 There is an issue open as of the last few hours and it seems like people are working on it.在过去的几个小时内有一个问题悬而未决,似乎人们正在解决这个问题。 I don't think it's anything to do with your Django/React project.我认为这与您的 Django/React 项目无关。

The issue ticket 出票

While the issue is being fixed: try installing node version 12.12.0 as shown below and run create-react-app again.在解决问题时:尝试安装节点版本 12.12.0,如下所示,然后再次运行 create-react-app。

nvm install 12.12.0
nvm use 12.12.0

it is a problem from node, Either you have to downgrade you node version or you can use Yarn try the following: So, apparently the issue is from npm and non of us has done anything wrong, still we can use Yarn to start a new react project while they solve it, follow the steps:这是节点的问题,要么您必须降级您的节点版本,要么您可以使用 Yarn 尝试以下操作:所以,显然问题出在 npm 并且我们没有做错任何事情,我们仍然可以使用 Yarn 开始一个新的在他们解决项目时对项目做出反应,请按照以下步骤操作:

step 1: yarn init -y第 1 步:纱线初始化 -y

step 2: Insert this to package.json第 2 步:将其插入 package.json

"resolutions": { "is-promise": "2.1.0", "run-async/is-promise": "2.1.0" } “决议”:{“is-promise”:“2.1.0”,“run-async/is-promise”:“2.1.0”}

step 3: yarn add --dev create-react-app第 3 步:纱线添加 --dev create-react-app

step 4: yarn create-react-app../my-app第 4 步:纱线创建反应应用程序../my-app

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM