【问题标题】:No solution, I still have this : "ng : command not found" [closed]没有解决方案,我仍然有这个:“ng:找不到命令”[关闭]
【发布时间】:2018-03-31 23:39:30
【问题描述】:

到目前为止,我设法运行 ng serve,但由于 4 或 5 天我无法解决问题,我尝试了网络上提出的所有解决方案,但没有任何效果......

这就是为什么我真诚地需要你的帮助! 我怎样才能翻新所有东西以确保它能够正常工作?

package.json: { "name": "cli-src", "version": "0.0.0", "license": "MIT", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e" }, "private": true, "dependencies": { "@angular/common": "^4.0.0", "@angular/compiler": "^4.0.0", "@angular/core": "^4.0.0", "@angular/forms": "^4.0.0", "@angular/http": "^4.0.0", "@angular/platform-browser": "^4.0.0", "@angular/platform-browser-dynamic": "^4.0.0", "@angular/router": "^4.0.0", "bootstrap": "^3.3.7", "core-js": "^2.4.1", "rxjs": "^5.1.0", "zone.js": "^0.8.4" }, "devDependencies": { "@angular/cli": "1.0.0", "@angular/compiler-cli": "^4.0.0", "@types/jasmine": "2.5.38", "@types/node": "~6.0.60", "codelyzer": "~2.0.0", "jasmine-core": "~2.5.2", "jasmine-spec-reporter": "~3.2.0", "karma": "~1.4.1", "karma-chrome-launcher": "~2.0.0", "karma-cli": "~1.0.1", "karma-jasmine": "~1.1.0", "karma-jasmine-html-reporter": "^0.2.2", "karma-coverage-istanbul-reporter": "^0.2.0", "protractor": "~5.1.0", "ts-node": "~2.0.0", "tslint": "~4.5.0", "typescript": "~2.2.0" } }

有关信息,我在 WINDOWS 上。

非常感谢愿意帮助我的人!

【问题讨论】:

  • 您需要提供您的错误信息的具体代码和详细信息。
  • 你试过了吗:npm uninstall @angular/cli -gnpm cache cleannpm install @angular/cli -g
  • 当我这样做时:npm cache clean 我有:npm ERR! As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use 'npm cache verify' instead. npm ERR! npm ERR! If you're sure you want to delete the entire cache, rerun this command with --force. npm ERR! A complete log of this run can be found in:npm ERR! C:\Users\bmmi\AppData\Roaming\npm-cache\_logs\2017-10-19T20_37_50_555Z-debug.log
  • 使用--force 开关
  • 检查 ng 是否在 node_modules\.bin 中。如果它在那里并且您仍然收到此错误。使用npm install -g <package-name>全局安装它

标签: node.js angular angular-cli


【解决方案1】:

1) 通过在命令行输入以下内容确保您已安装 Angular cli:ng -v

2) 确保您位于包含 package.json 文件的文件夹中。要确认,请导航到您正在使用的文件夹并列出文件。

3) 打开package.json 文件并确保它有一个定义了适当脚本的脚本部分。

  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },

4) 确保您已安装应用程序的所有软件包。要确认,请确保node_modules 文件夹与package.json 文件位于同一位置。绝对确定,导航到包含package.json 文件的文件夹并输入npm install

【讨论】:

  • 谢谢你的回答,当我做ng -v 时,我得到了ng : command not found。我做了你所有的建议,这个项目在 4 天前工作,我想删除所有并重新启动,但我没有我可以删除的。
  • 听起来您不再拥有 Angular CLI。看起来上面的其他人正在指导您如何解决这个问题。
  • @DeborahK 他使用 windows,我认为他应该指定 ng 的绝对路径,即 "ng": "node_modules\.bin\ng"
  • 没有。我使用 windows,如果使用 -g 标志安装,则不需要绝对路径。
  • 我在 node_modules/.bin/ 中有 ng 但无法识别
【解决方案2】:

这似乎是使用 Bash 的问题。考虑不要在 Windows 中使用 Bash。 (我没有)。

如果您需要继续使用 Bash,请在此处查看扩展信息集:https://github.com/angular/angular-cli/issues/5021

如果您使用的是 Windows:

1) 右击左下角的开始按钮,选择Run

2) 选择打开cmd,这可能已经是默认设置了。

3) 单击确定。这应该会打开一个命令提示符。

4) 键入前面指定的命令,一次一个:

npm uninstall @angular/cli -g
npm cache --force clean
npm install @angular/cli -g

5) 键入 ng -v,您现在应该已经正确安装了 CLI。

【讨论】:

  • 我可以使用 nodejs 命令提示符,但是你能告诉我我必须使用哪个命令
  • 当我这样做的时候我就有了:npm cache cleannpm ERR! As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use 'npm cache verify' instead. npm ERR! npm ERR! If you're sure you want to delete the entire cache, rerun this command with --force. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\bmmi\AppData\Roaming\npm-cache\_logs\2017-10-19T21_24_15_481Z-debug.log
  • 使用npm cache --force clean
  • 对于npm install @angular/cli -gC:\Users\bmmi\.npm-global\ng -> C:\Users\bmmi\.npm-global\node_modules\@angular\cli\bin\ng > node-sass@4.5.3 install C:\Users\bmmi\.npm-global\node_modules\@angular\cli\node_modules\node-sass > node scripts/install.js Cached binary found at C:\Users\bmmi\AppData\Roaming\npm-cache\node-sass\4.5.3\win32-x64-48_binding.node > uglifyjs-webpack-plugin@0.4.6 postinstall C:\Users\bmmi\.npm-global\node_modules\@angular\cli\node_modules\uglifyjs-webpack-plugin > node lib/post_install.js [...]
  • [...] > node-sass@4.5.3 postinstall C:\Users\bmmi\.npm-global\node_modules\@angular\cli\node_modules\node-sass > node scripts/build.js Binary found at C:\Users\bmmi\.npm-global\node_modules\@angular\cli\node_modules\node-sass\vendor\win32-x64-48\binding.node Testing binary Binary is fine + @angular/cli@1.4.8 added 786 packages and updated 1 package in 65.285s
猜你喜欢
  • 2021-01-07
  • 1970-01-01
  • 1970-01-01
  • 2013-09-20
  • 2018-09-22
  • 2023-03-10
  • 1970-01-01
  • 2017-12-18
  • 2021-03-11
相关资源
最近更新 更多