当前位置:   article > 正文

AngularJS安装版本问题_angular-cli node 版本

angular-cli node 版本

一、安装

        Angular CLI 脚手架安装命令:

npm install -g @angular/cli

        在安装前请确保自己安装NodeJS环境版本为V18及以上,否则会因node版本问题导致项目无法正常运行。

        脚手架安装后,已提示了当前node版本必须为18.13.0或大于20.9.0版本:

        在node版本不一致情况下,创建项目会提示Node.js版本必须为v18.13,如下图:

      

二、匹配版本

        本人电脑上使用的node版本为v16,在不升级node版本情况下,可以考虑降低@angular/cli版本,地址:Releases · angular/angular-cli · GitHub

        2.1 安装命令

        在Releases中找到对应版本进行安装,命令如下:

npm install -g @angular/cli@16.2.6

        此时则没有版本问题提示了,如下图:

        2.2 创建项目

  1. D:\workspace\web\angular>ng new hello-world
  2. ? Would you like to share pseudonymous usage data about this project with the Angular Team
  3. at Google under Google's Privacy Policy at https://policies.google.com/privacy. For more
  4. details and how to change this setting, see https://angular.io/analytics. Yes
  5. Thank you for sharing pseudonymous usage data. Should you change your mind, the following
  6. command will disable this feature entirely:
  7. ng analytics disable --global
  8. Global setting: enabled
  9. Local setting: No local workspace configuration file.
  10. Effective status: enabled
  11. ? Would you like to add Angular routing? Yes
  12. ? Which stylesheet format would you like to use? SCSS [ https://sass-lang.com/documentation/syntax#scss
  13. ]
  14. CREATE hello-world/angular.json (2899 bytes)
  15. CREATE hello-world/package.json (1042 bytes)
  16. CREATE hello-world/README.md (1064 bytes)
  17. CREATE hello-world/tsconfig.json (901 bytes)
  18. CREATE hello-world/.editorconfig (274 bytes)
  19. CREATE hello-world/.gitignore (548 bytes)
  20. CREATE hello-world/tsconfig.app.json (263 bytes)
  21. CREATE hello-world/tsconfig.spec.json (273 bytes)
  22. CREATE hello-world/.vscode/extensions.json (130 bytes)
  23. CREATE hello-world/.vscode/launch.json (470 bytes)
  24. CREATE hello-world/.vscode/tasks.json (938 bytes)
  25. CREATE hello-world/src/main.ts (214 bytes)
  26. CREATE hello-world/src/favicon.ico (948 bytes)
  27. CREATE hello-world/src/index.html (296 bytes)
  28. CREATE hello-world/src/styles.scss (80 bytes)
  29. CREATE hello-world/src/app/app-routing.module.ts (245 bytes)
  30. CREATE hello-world/src/app/app.module.ts (393 bytes)
  31. CREATE hello-world/src/app/app.component.html (23115 bytes)
  32. CREATE hello-world/src/app/app.component.spec.ts (1006 bytes)
  33. CREATE hello-world/src/app/app.component.ts (216 bytes)
  34. CREATE hello-world/src/app/app.component.scss (0 bytes)
  35. CREATE hello-world/src/assets/.gitkeep (0 bytes)
  36. √ Packages installed successfully.
  37. warning: LF will be replaced by CRLF in .editorconfig.
  38. The file will have its original line endings in your working directory
  39. warning: LF will be replaced by CRLF in .gitignore.
  40. The file will have its original line endings in your working directory
  41. warning: LF will be replaced by CRLF in .vscode/extensions.json.
  42. The file will have its original line endings in your working directory
  43. warning: LF will be replaced by CRLF in .vscode/launch.json.
  44. The file will have its original line endings in your working directory
  45. warning: LF will be replaced by CRLF in .vscode/tasks.json.
  46. The file will have its original line endings in your working directory
  47. warning: LF will be replaced by CRLF in README.md.
  48. The file will have its original line endings in your working directory
  49. warning: LF will be replaced by CRLF in angular.json.
  50. The file will have its original line endings in your working directory
  51. warning: LF will be replaced by CRLF in package-lock.json.
  52. The file will have its original line endings in your working directory
  53. warning: LF will be replaced by CRLF in package.json.
  54. The file will have its original line endings in your working directory
  55. warning: LF will be replaced by CRLF in src/app/app-routing.module.ts.
  56. The file will have its original line endings in your working directory
  57. warning: LF will be replaced by CRLF in src/app/app.component.html.
  58. The file will have its original line endings in your working directory
  59. warning: LF will be replaced by CRLF in src/app/app.component.spec.ts.
  60. The file will have its original line endings in your working directory
  61. warning: LF will be replaced by CRLF in src/app/app.component.ts.
  62. The file will have its original line endings in your working directory
  63. warning: LF will be replaced by CRLF in src/app/app.module.ts.
  64. The file will have its original line endings in your working directory
  65. warning: LF will be replaced by CRLF in src/index.html.
  66. The file will have its original line endings in your working directory
  67. warning: LF will be replaced by CRLF in src/main.ts.
  68. The file will have its original line endings in your working directory
  69. warning: LF will be replaced by CRLF in src/styles.scss.
  70. The file will have its original line endings in your working directory
  71. warning: LF will be replaced by CRLF in tsconfig.app.json.
  72. The file will have its original line endings in your working directory
  73. warning: LF will be replaced by CRLF in tsconfig.json.
  74. The file will have its original line endings in your working directory
  75. warning: LF will be replaced by CRLF in tsconfig.spec.json.
  76. The file will have its original line endings in your working directory
  77. Successfully initialized git.

       2.3 运行项目

        选择项目目录:

D:\workspace\web\angular>cd hello-world

        运行hello-world项目命令如下:

  1. D:\workspace\web\angular\hello-world>ng serve --open
  2. ? Would you like to share pseudonymous usage data about this project with the Angular Team
  3. at Google under Google's Privacy Policy at https://policies.google.com/privacy. For more
  4. details and how to change this setting, see https://angular.io/analytics. Yes
  5. Thank you for sharing pseudonymous usage data. Should you change your mind, the following
  6. command will disable this feature entirely:
  7. ng analytics disable
  8. Global setting: enabled
  9. Local setting: enabled
  10. Effective status: enabled
  11. √ Browser application bundle generation complete.
  12. Initial Chunk Files | Names | Raw Size
  13. vendor.js | vendor | 2.35 MB |
  14. polyfills.js | polyfills | 333.17 kB |
  15. styles.css, styles.js | styles | 230.92 kB |
  16. main.js | main | 48.74 kB |
  17. runtime.js | runtime | 6.52 kB |
  18. | Initial Total | 2.96 MB
  19. Build at: 2024-02-26T08:05:28.353Z - Hash: daa545468f767600 - Time: 33009ms
  20. ** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
  21. √ Compiled successfully.

        运行结果下图:

        如上图,项目可以正常运行了。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/557734
推荐阅读
相关标签
  

闽ICP备14008679号