我遇到了无法使用 npx 命令创建 react 应用程序的问题 [英] I'm having a problem that can't create react app using npx command

查看:82
本文介绍了我遇到了无法使用 npx 命令创建 react 应用程序的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用 npx create-react-app 来创建我的 React 项目.

I can't use npx create-react-app <projectname> to create my react project.

控制台给出这个:

必须使用import来加载ES模块:C:\Users\user\AppData\Roaming\npm-cache\_npx\4536\node_modules\create-react-app\node_modules\is-promise\index.js//不支持 ES 模块的 require().//C:\Users\user\AppData\Roaming\npm-cache\_npx\4536\node_modules\create-react-app\node_modules\is-promise\index.js 的 require() 来自 C:\Users\user\AppData\Roaming\npm-cache\_npx\4536\node_modules\create-react-app\node_modules\run-async\index.js 是一个 ES 模块文件,因为它是一个 .js 文件,其最近的父 package.json 包含类型":module" 将包范围内的所有 .js 文件定义为 ES 模块.//而是将 C:\Users\user\AppData\Roaming\npm-cache\_npx\4536\node_modules\create-react-app\node_modules\is-promise\index.js 重命名为以 .cjs 结尾,更改需要使用的代码import(),或从 C:\Users\user\AppData\Roaming\npm-cache\_npx\4536\node_modules\create-react-app\node_modules\is-promise\package.json 中删除 "type": "module".

推荐答案

在安装 create-react-app 之前清理你的 npm 缓存.

Clean your npm cache before installing create-react-app.

npm cache clean --force

然后全局安装 create-react-app.

npm install -g create-react-app

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

create-react-app my-app

然后导航到 my-app 并运行

Then navigate to my-app and run

npm start

这篇关于我遇到了无法使用 npx 命令创建 react 应用程序的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆