简体   繁体   English

ng serve命令无法正常工作5

[英]ng serve command not working angular 5

If I run ng serve, getting this error 如果我运行ng serve,则会收到此错误

ng : The term 'ng' is not recognized as the name of a cmdlet, function, script file, or operable program. ng:术语“ ng”未被识别为cmdlet,函数,脚本文件或可运行程序的名称。 Check the spelling of the name, or if a path was included, verify that the path is correct and try again. 检查名称的拼写,或者是否包含路径,请验证路径是否正确,然后重试。 At line:1 char:1 + ng serve + ~~ + CategoryInfo : ObjectNotFound: (ng:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException 在第1行:char:1 + ng服务+ ~~ + CategoryInfo:ObjectNotFound:(ng:String)[],CommandNotFoundException + FullyQualifiedErrorId:CommandNotFoundException

I have tried npm run ng serve, getting this error 我已经尝试过npm run ng serve,收到此错误

Local workspace file ('angular.json') could not be found. 找不到本地工作区文件('angular.json')。 Error: Local workspace file ('angular.json') could not be found. 错误:找不到本地工作空间文件('angular.json')。 at WorkspaceLoader._getProjectWorkspaceFilePath (C:\\Users\\rohit\\AppData\\Roaming\\npm\\node_modules\\@angular\\cli\\models\\workspace-loader.js:3 7:19) at WorkspaceLoader.loadWorkspace (C:\\Users\\rohit\\AppData\\Roaming\\npm\\node_modules\\@angular\\cli\\models\\workspace-loader.js:24:21) at ServeCommand._loadWorkspaceAndArchitect (C:\\Users\\rohit\\AppData\\Roaming\\npm\\node_modules\\@angular\\cli\\models\\architect-command.js:180:3 2) at ServeCommand. 在WorkspaceLoader.loadWorkspace(C:\\ Users \\ rohit \\ AppData \\ Roaming \\ npm \\ node_modules \\ @angular \\ cli \\ models \\ workspace-loader.js:3 7:19)上的WorkspaceLoader.loadWorkspace(C:\\ Users \\ rohit \\位于ServeCommand._loadWorkspaceAndArchitect(C:\\ Users \\ rohit \\ AppData \\ Roaming \\ npm \\ node_modules \\ @angular \\ cli \\的AppData \\ Roaming \\ npm \\ node_modules \\ @angular \\ cli \\ models \\ workspace-loader.js:24:21) models \\ architect-command.js:180:3 2)在ServeCommand处。 (C:\\Users\\rohit\\AppData\\Roaming\\npm\\node_modules\\@angular\\cli\\models\\architect-command.js:47:25) at Generator.next () at C:\\Users\\rohit\\AppData\\Roaming\\npm\\node_modules\\@angular\\cli\\models\\architect-command.js:7:71 at new Promise () at __awaiter (C:\\Users\\rohit\\AppData\\Roaming\\npm\\node_modules\\@angular\\cli\\models\\architect-command.js:3:12) at ServeCommand.initialize (C:\\Users\\rohit\\AppData\\Roaming\\npm\\node_modules\\@angular\\cli\\models\\architect-command.js:46:16) at Object. (C:\\ Users \\ rohit \\ AppData \\ Roaming \\ npm \\ node_modules \\ @angular \\ cli \\ models \\ architect-command.js:47:25)在Generator.next()在C:\\ Users \\ rohit \\ AppData \\ Roaming \\ npm \\ node_modules \\ @angular \\ cli \\ models \\ architect-command.js:7:71在__awaiter处的新Promise()(C:\\ Users \\ rohit \\ AppData \\ Roaming \\ npm \\ node_modules \\ @angular \\ cli \\ models \\ ServeCommand.initialize(C:\\ Users \\ rohit \\ AppData \\ Roaming \\ npm \\ node_modules \\ @angular \\ cli \\ models \\ architect-command.js:46:16)中的\\ architect-command.js:3:12) 。 (C:\\Users\\rohit\\AppData\\Roaming\\npm\\node_modules\\@angular\\cli\\models\\command-runner.js:87:23) npm ERR! (C:\\ Users \\ rohit \\ AppData \\ Roaming \\ npm \\ node_modules \\ @angular \\ cli \\ models \\ command-runner.js:87:23)npm ERR! code ELIFECYCLE npm ERR! 代码ELIFECYCLE npm ERR! errno 1 npm ERR! errno 1 npm错误! npv2@0.0.0 ng: ng "serve" npm ERR! npv2@0.0.0 ng: ng "serve" npm ERR! Exit status 1 npm ERR! 退出状态1 npm ERR! npm ERR! npm ERR! Failed at the npv2@0.0.0 ng script. 在npv2@0.0.0 ng脚本处失败。 npm ERR! npm ERR! This is probably not a problem with npm. npm可能不是问题。 There is likely additional logging output above. 上面可能还有其他日志记录输出。

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\rohit\AppData\Roaming\npm-cache\_logs\2018-06-12T06_59_12_392Z-debug.log

I have uninstall @angular/cli and cleared the cached, again installed but facing same issue. 我已经卸载@ angular / cli并清除了缓存,再次安装但面临相同的问题。

Kindly suggest. 请提示。

This could be due to different versions of angular-cli. 这可能是由于angular-cli版本不同所致。 Check the version of angular-cli, you should not have version 6, but use 1.7. 检查angular-cli的版本,您不应拥有版本6,而应使用1.7。 Cause in angular 6 the configuration is in angular.json file. 原因是在angular 6中,配置位于angular.json文件中。 In version 1.7 the configuration is in angular-cli.json 在1.7版中,配置位于angular-cli.json中

This may work 这可能有效

add your your npm folder path and angular-cli\\bin folder path to environment variables 将您的npm文件夹路径和angular-cli \\ bin文件夹路径添加到环境变量

C:\Users\YourPcName\AppData\Roaming\npm`
C:\Users\YoutPcName\AppData\Roaming\npm\node_modules\angular-cli\bin`
> npm start

将解决您的问题,因为它解决了我的问题

You have two issues here. 您在这里有两个问题。 You are trying to run global angular-cli commands without having the angular cli globally installed. 您正在尝试运行全局angular-cli命令,而未全局安装角度cli。 You could solve this by installing the CLI globally using npm i -g @angular/cli The next issue you have is that when using the project angular cli, you upgraded the cli but not the project itself. 您可以通过使用npm i -g @angular/cli全局安装CLI来解决此问题。下一个问题是,在使用项目angular cli时,您升级了cli,但没有升级项目本身。 You can either reinstall an older cli by changing the version in your package.json, or upgrade your package using the awesome new schematics. 您可以通过更改package.json中的版本来重新安装较旧的cli,也可以使用令人敬畏的新原理图升级软件包。 For this I'd advise you to read the upgrade guide . 为此,我建议您阅读升级指南

If you don't feel like reading, and feel especially lucky today, you can just download the 6.0 cli globally in the way mentioned above, and run ng update 如果您不喜欢阅读,并且今天感到特别幸运,则可以按照上述方式在全球范围内下载6.0 cli,然后运行ng update

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

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