【问题标题】:Error when running npx create-react-app myapp on fresh install of node.js在全新安装 node.js 时运行 npx create-react-app myapp 时出错
【发布时间】:2022-02-10 21:42:32
【问题描述】:

我关注了 reactjs.org 网站的 create-react-app 到一个 T

我无法在任何地方找到这个特定的错误,而且大多数帖子都是几年前的; 无论如何与帖子中的具体错误无关。

有没有人遇到过这种情况,你做了什么来解决它?

最新版本的 Win10,如果有帮助的话。 Node.js的LTS版本v16.14.0

我的 Node.js 安装只是在操作系统驱动器上的一个干净的 express 安装。有什么想法吗?

运行npx create-react-app my-app后,错误消息如下:

C:\Users\Keith & Vanny>npx create-react-app myapp
'Vanny\AppData\Local\npm-cache\_npx\c67e74de0542c87c\node_modules\.bin\' is not recognized as 
an internal or external command,
operable program or batch file.
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module 'C:\Users\create-react-app\index.js'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

更新:我通过npm i create-react-app在本地安装它并尝试使用npm init react-app my-app创建。

它们都产生上述相同的错误。我认为这与运行批处理脚本的错误的 unrecognized command 部分有关,它无法解析和完成工作,然后没有安装包。所以 javascript 行话告诉我我缺少必需的包;我的paths for Node 是完美的。 清理安装并清理所有软件包。这让我很困惑。 看来如果我们不能解决这个问题,我会去找开发人员。

【问题讨论】:

  • 你的节点是什么版本?
  • @HritikSharma LTS 版本 v16.14.0
  • 我会仔细检查您是否无意中安装了create-react-appThe CRA docs 有检查说明。
  • @ReedDunkle 该节点安装在以前没有安装节点本身的机器上。根据 reactjs 站点,您甚至不需要通过 npm 安装软件包。单线 npx 命令可以即时完成所有这些工作。我的机器上没有 npm install create-react-app
  • @KeithCronin 是的,他们希望你仔细检查你没有安装它,因为 npx 处理它。不过,听起来这不是问题。不幸的是,我没有任何其他想法。

标签: node.js reactjs


【解决方案1】:

创建一个本地管理员帐户,它只是一个没有符号或空格的字符串,登录到该帐户,然后运行 ​​npx 命令完美。

在 Windows 机器上安装 ReactJs 的 users/ 路径包含符号和空格,特别是符号,会导致错误发生,其中 npx/npm 甚至 create-react-app 无法正确解析模块的路径,因此引发找不到模块错误。

经验教训:永远不要在您的 Windows 用户名中添加符号。很郁闷,但我肯定必须在本地帐户上开发。

更新:因为我拒绝使用虚拟管理员帐户进行开发,我发现 2022 年在 Win 10 Home 上运行的完美解决方案非常好。只需在执行此操作之前创建一个系统还原点。这是链接! StackExchange solution for properly renaming a faulty conflicting system username. Use the second solution, not the accepted answer.

准备好花几个小时编辑您的注册表。

Direct link to the solution I'm talking about.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-17
    • 2022-06-14
    • 1970-01-01
    • 2021-09-11
    • 2023-02-14
    • 1970-01-01
    • 2020-11-13
    • 2020-04-19
    相关资源
    最近更新 更多