【问题标题】:Visual Studio 2022: Cannot create a project named "tempProjectCreation" because of npm naming restrictionsVisual Studio 2022:由于 npm 命名限制,无法创建名为“tempProjectCreation”的项目
【发布时间】:2022-12-11 13:55:16
【问题描述】:

我正在尝试在 Visual Studio 2022 Community Edition 中创建一个新的 Typescript 项目。

我已经安装了 Visual Studio 2022 Community Edition (Windows),以及适用于 Windows 的 Node.JS v18.12.1-x64。

在 Visual Studio 安装程序 (v17.4.2) 中,我单击“Node.js 开发”工作负载并安装它。

然后,我打开 Visual Studio 2022 Community 并从“创建新项目”页面单击“独立 Typescript React 项目”。

创建项目时,命令窗口打开,从 Visual Studio 启动的命令窗口 (cmd.exe) 中出现以下错误:

C:\Program Files\nodejs\npx.cmd --yes create-react-app "C:\Users\Admin\source\reactproject1\tempProjectCreation" --use-npm --template typescript && cd /D C:\Users\Admin\source\reactproject1\tempProjectCreation && npm i --save-dev jest-editor-support eslint-config-react-app
Cannot create a project named "tempProjectCreation" because of npm naming restrictions:

  * name can no longer contain capital letters

Please choose a different project name.
Press any key to continue . . .

IDE 无法创建新的 React 模板站点。显然,出于文件可移植性的原因,Node.js 现在禁止使用大写字母。

解决方案看起来很简单(正如错误指出的那样)——只需将“tempProjectCreation”的名称更改为“tempprojectcreation”(小写),它就应该可以工作。事实上,我执行了上面的“npx.cmd”命令并将 tempProjectCreation 重命名为 tempprojectcreation“并且网站生成没有问题!!

我用谷歌搜索并搜索了我的硬盘,但找不到可能引发错误的 Visual Studio 模板脚本。事实上,我找不到 Visual Studio 模板脚本的存储位置

  1. Visual Studio 模板脚本在哪里?我查看了 "C:\Users{UserName}\AppData\Local\Microsoft\VisualStudio\17.0_0d978569 并且它们似乎不存在。

  2. 它们是可编辑的吗?是否可以将“tempProjectCreation”更改为小写的“tempprojectcreation”?

    由于这是一个配置问题,我不确定除了上面发出的错误之外我是否遗漏了任何调试信息,但我会在必要时编辑这个问题。

【问题讨论】:

    标签: visual-studio-2022 react-typescript npx


    【解决方案1】:

    以下是我为了能够使用 Visual Studio 2022(在 Windows 上)创建独立的 React Typescript 项目而采取的步骤:

    1. 打开 Windows 控制台 (cmd) 并卸载然后在本地重新安装 create-react-app :

      npm uninstall -g create-react-app

      npm install -g create-react-app

    2. 导航到此文件夹:C:Users[您的用户名]AppDataRoaming 下午 ode_modulesalidate-npm-包名称

    3. 编辑 index.js 并注释掉这些代码行:

      如果(名称.toLowerCase()!==名称){ warnings.push('名字不能再包含大写字母') }

    【讨论】:

      猜你喜欢
      • 2011-12-23
      • 2022-10-09
      • 2021-12-24
      • 1970-01-01
      • 2022-06-13
      • 1970-01-01
      • 2021-11-28
      • 2012-08-28
      • 1970-01-01
      相关资源
      最近更新 更多