简体   繁体   English

@ angular / cli安装后无法正常工作

[英]@angular/cli not working after installation

I have installed the @angular/cli on my MacBook machine. 我在我的MacBook机器上安装了@ angular / cli。 Node server version is v6.9.5 and the npm version is 3.10.10. 节点服务器版本为v6.9.5,npm版本为3.10.10。 I have ran the following command to install the @angular/cli. 我运行了以下命令来安装@ angular / cli。

sudo npm install -g @angular-cli sudo npm install -g @ angular-cli

When I run the ng help command or any command for ng. 当我运行ng help命令或任何ng命令时。 It shows me the following error 它向我显示以下错误

Parsing .angular-cli.json failed. 解析.angular-cli.json失败了。 Please make sure your .angular-cli.json is valid JSON. 请确保您的.angular-cli.json是有效的JSON。 Error: SyntaxError: Unexpected token u in JSON at position 22 错误:SyntaxError:位于22的JSON中的意外标记u

InvalidConfigError: Parsing .angular-cli.json failed. Please make sure your 
.angular-cli.json is valid JSON. 
Error: SyntaxError: Unexpected token u in JSON at position 22
   at InvalidConfigError (/usr/local/lib/node_modules/@angular/cli/models/config/config.js:10:9)
   at Function.fromConfigPath (/usr/local/lib/node_modules/@angular/cli/models/config/config.js:77:19)
   at Function.fromProject (/usr/local/lib/node_modules/@angular/cli/models/config.js:96:46)
   at Object.<anonymous> (/usr/local/lib/node_modules/@angular/cli/commands/build.js:7:35)
   at Module._compile (module.js:570:32)
   at Object.Module._extensions..js (module.js:579:10)
   at Module.load (module.js:487:32)
   at tryModuleLoad (module.js:446:12)
   at Function.Module._load (module.js:438:3)
   at Module.require (module.js:497:17)

I also uninstalled and @angualr/cli and clear the cache then reinstalled @angualr/cli. 我也卸载了@ angualr / cli并清除缓存然后重新安装@ angualr / cli。 I run the following command. 我运行以下命令。

sudo npm uninstall -g @angular-cli 
npm cache clean sudo 
npm install -g @angular-cli

Still the same issue is appearing. 仍然出现同样的问题。

该包被称为@angular/cli ,所以npm install -g @angular/cli

@angular-cli is the previous version. @angular-cli是以前的版本。 Now you need to 现在你需要

npm install -g @angular/cli

to work with @angular/cli version 使用@angular/cli版本

The package you mentioned is not valid. 您提到的包裹无效。 For fresh installation use npm install -g @angular/cli . 对于全新安装,请使用npm install -g @angular/cli Check here for more details https://github.com/angular/angular-cli#installation 点击此处了解更多详情https://github.com/angular/angular-cli#installation


Also If you are upgrading follow this https://github.com/angular/angular-cli#updating-angular-cli 此外,如果您正在升级,请按照此https://github.com/angular/angular-cli#updating-angular-cli进行操作


If you upgrading from a beta/RC version follow this https://github.com/angular/angular-cli/wiki/stories-1.0-update 如果您从beta / RC版本升级,请按照https://github.com/angular/angular-cli/wiki/stories-1.0-update


angular-cli uses angular.cli.json. angular-cli使用angular.cli.json。 whereas @angular/cli uses .angular.cli.json @angular/cli使用.angular.cli.json

i also face same issue, so i tried this method given below. 我也面临同样的问题,所以我尝试了下面给出的这种方法。

Clean uninstall of angular-cli, like npm uninstall -g angular-cli Clone this angular-cli repo, Go to the angular-cli repo folder, and run npm link, Go to my project folder Run npm link angular-cli Now to run ng command, I use ./node_modules/angular-cli/bin/ng from my project folder 清除卸载angular-cli,如npm uninstall -g angular-cli克隆此angular-cli repo,转到angular-cli repo文件夹,然后运行npm链接,转到我的项目文件夹运行npm link angular-cli现在运行ng命令,我使用项目文件夹中的./node_modules/angular-cli/bin/ng

你需要全局安装@ angular / cli才能在任何地方使用它。要全局安装它使用cmd'npm i -g @ angular / cli',其中-g表示global.Even将你的角度版本更新为latest.I认为错误是因为在较旧版本的angular中,angular.json文件名曾经以不同方式保存,其名称在新版本或最新版本中保存的方式不同,因此安装后可能无法读取angular.json文件。

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

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