简体   繁体   English

Angular CLI v13 - 无法运行“ng”命令

[英]Angular CLI v13 - Can not run "ng" commands

I upgraded Angular CLI to v13 globally, and when I try to use ng command it gives me this error:我将 Angular CLI 全局升级到v13 ,当我尝试使用ng命令时,它给了我这个错误:

在此处输入图片说明

I saw here that Angular v13 is compatible with Node v16.10.x so I installed Node v16.10.0 and it does not work again.我在这里看到 Angular v13 与 Node v16.10.x兼容,所以我安装了 Node v16.10.0 ,但它再次无法工作。

I perform standard operations:我执行标准操作:

npm uninstall -g @angular/cli
npm install -g @angular/cli@latest

I even try to clear npm cache and it still didn't work.我什至尝试清除npm缓存,但仍然无效。

When I downgrade it and install Angular CLI v12 globally, everything works again.当我降级它并全局安装 Angular CLI v12 ,一切又v12正常。

Is this some known Angular CLI v13 issue?这是一些已知的 Angular CLI v13问题吗?

Environment:环境:

Windows 10 (win32 x64)

我觉得你需要把ng.js文件编码格式bom+utf8改成utf8

On Windows .js files are associated to Windows Scripting Host by default, so the script will not be run with Node.在 Windows 上,默认情况下.js文件与Windows Scripting Host相关联,因此脚本不会与 Node.js 一起运行。 You can open explorer and find a .js file, you can check that it's not considered JavaScript.您可以打开资源管理器并找到一个.js文件,您可以检查它是否不被视为 JavaScript。

Open a JavaScript file's properties and in the associated programs (or open with), link the node.js exe file to open that kind of files.打开 JavaScript 文件的属性,并在相关程序(或打开方式)中链接 node.js exe文件以打开此类文件。

  1. Use the following command to delete your version使用以下命令删除您的版本

 npm uninstall -g @angular/cli

  1. Unistall the node file with the following command使用以下命令卸载节点文件

 npm uninstall

  1. Go to your computer's file explorer Enter drive C. In the "search This PC" section, search for the word "App Data" and then "Roaming" Delete your "npm" file in the "Roaming" folder转到计算机的文件资源管理器输入驱动器 C。在“搜索此电脑”部分中,搜索“应用数据”一词,然后搜索“漫游”删除“漫游”文件夹中的“npm”文件
  2. Enter the "npm install" command again再次输入“npm install”命令
  3. Now it's time to enter the command "npm install -g @ angular / cli"现在是时候输入命令“npm install -g @angular/cli”

I am going to suggest you an alternative solution, which is the one I use to face the problems that gave me having only one version of node and having many different projects: TO USE A NODE MANAGER我将向您建议另一种解决方案,这是我用来面对问题的解决方案,这些问题使我只有一个版本的节点并拥有许多不同的项目:使用节点管理器

I would recomend you Volta , a hassle-free way to manage your JavaScript command-line tool.我会向您推荐Volta ,这是一种管理 JavaScript 命令行工具的轻松方式。

Just download its installable from here: https://github.com/volta-cli/volta/releases/download/v1.0.5/volta-1.0.5-windows-x86_64.msi and run it (with administrator permissions) to install it.只需从这里下载它的可安装程序: https : //github.com/volta-cli/volta/releases/download/v1.0.5/volta-1.0.5-windows-x86_64.msi并运行它(具有管理员权限)进行安装它。

Once you have it installed, just run: volta install node@16 (or use another particular version of Node) It will install a new version of node, but "in a different way", although it will be transparent to you:安装后,只需运行: volta install node@16 (或使用另一个特定版本的节点)它将安装新版本的节点,但“以不同的方式”,尽管它对您来说是透明的:

Volta does not use any fancy OS features or shell-specific hooks. Volta 不使用任何花哨的操作系统功能或特定于 shell 的钩子。 It's built on the simple, proven approach of shims.它建立在简单、经过验证的垫片方法之上。 Whenever you install a tool with Volta, it adds a shim to your PATH that acts as an intelligent (and fast) router to the right version of the tool and runs it with the right Node engine.每当您使用 Volta 安装工具时,它都会向您的 PATH 添加一个 shim,充当该工具正确版本的智能(且快速)路由器,并使用正确的 Node 引擎运行它。 Volta is easy to install, with no external dependencies, because it's built in Rust as a single, fast native executable. Volta 易于安装,没有外部依赖项,因为它是在 Rust 中构建的,作为一个单一的、快速的本机可执行文件。

https://docs.volta.sh/guide/getting-started https://docs.volta.sh/guide/getting-started

I hope this solution works for you 👇 1.Remove the user environment variable我希望这个解决方案对你有用👇 1.删除用户环境变量

C:\\Users\\AppData\\Roaming\\npm\\node_modules@angular\\cli\\bin C:\\Users\\AppData\\Roaming\\npm\\node_modules@angular\\cli\\bin

2.uninstall angular 3.uninstall nodejs 4.reboot your pc 5.reinstall nodejs & angular 2.uninstall angular 3.uninstall nodejs 4.reboot your pc 5.reinstall nodejs & angular

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

相关问题 Angular 从 v12 迁移到 v13:模块<typescript>只能使用“allowSyntheticDefaultImports”标志默认导入</typescript> - Angular Migrate from v12 to v13: Module <typescript> can only be default-imported using the 'allowSyntheticDefaultImports' flag 找不到模块“@angular/cdk/dialog”- Angular 将 v13 升级到 v14 问题 - Cannot find module '@angular/cdk/dialog' - Angular upgrade v13 to v14 issue Angular 5 错误 (Angular CLI) - 无法运行 ng build --prod - Angular 5 Error (Angular CLI) - Can't run ng build --prod 升级 angular v12 到 v13 时出现找不到模块错误 - Getting Module not found error when upgrade angular v12 to v13 将 Angular v12 升级到 v13 后未捕获 TypeError - Uncaught TypeError after upgrading Angular v12 to v13 Angular Cli:弹出后我不能使用ng命令参数,是否可以使用ng params替代? - Angular Cli: after eject i can't use ng commands parameters, any alternatives for ng params? 我应该如何在 Angular v13 中提取 @angular/material css 文件? - How should I extract @angular/material css file in Angular v13? 无法在我的angular-cli项目上运行ng lint - Can't run ng lint on my angular-cli project Angular 更新到最新 v13 后无法设置属性 ɵfac - Cannot set property ɵfac after Angular update to latest v13 升级到 Angular v13 后,每次更改都会修改附加缓存文件 - After upgrade to Angular v13, Additional cache files modified on each change
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM