angular - 使用“ng generate”或“ng add”时出错
问题描述
所以我在 Termux Android ARM 中使用 Angular 版本 8。这是来自 Angular CLI 的 Angular 版本信息:
$ ng version
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 8.0.2
Node: 12.4.0
OS: android arm
Angular: <error>
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
但是当我使用ng add
命令为我的网站项目添加 PWA 和 service worker 时,它返回错误:
$ ng add @angular/pwa --project betaleapofazzamgithubio
Workspace needs to be loaded before it is used.
Error: Workspace needs to be loaded before it is used.
at Workspace._assertLoaded (/data/data/com.termux/files/home/node_modules/@angular-devkit/core/src/experimental/workspace/workspace.js:108:19)
at Workspace.getProjectByPath (/data/data/com.termux/files/home/node_modules/@angular-devkit/core/src/experimental/workspace/workspace.js:156:14)
at getProjectByCwd (/data/data/com.termux/files/home/node_modules/@angular/cli/utilities/config.js:103:26)
at Object.getConfiguredPackageManager (/data/data/com.termux/files/home/node_modules/@angular/cli/utilities/config.js:116:25)
at Object.getPackageManager (/data/data/com.termux/files/home/node_modules/@angular/cli/utilities/package-manager.js:32:35)
at new AddCommand (/data/data/com.termux/files/home/node_modules/@angular/cli/commands/add-impl.js:25:49)
at Object.runCommand (/data/data/com.termux/files/home/node_modules/@angular/cli/models/command-runner.js:172:25)
at async default_1 (/data/data/com.termux/files/home/node_modules/@angular/cli/lib/cli/index.js:32:31)
因为错误,我使用ng generate
命令而不是ng add
命令。但它也返回错误。这是错误:
$ ng generate service-worker
Workspace needs to be loaded before it is used.
Error: Workspace needs to be loaded before it is used.
at Workspace._assertLoaded (/data/data/com.termux/files/home/node_modules/@angular-devkit/core/src/experimental/workspace/workspace.js:108:19)
at Workspace.getProjectByPath (/data/data/com.termux/files/home/node_modules/@angular-devkit/core/src/experimental/workspace/workspace.js:156:14)
at Object.getProjectByCwd (/data/data/com.termux/files/home/node_modules/@angular/cli/utilities/config.js:103:26)
at GenerateCommand.getDefaultSchematicCollection (/data/data/com.termux/files/home/node_modules/@angular/cli/models/schematic-command.js:251:38)
at GenerateCommand.parseSchematicInfo (/data/data/com.termux/files/home/node_modules/@angular/cli/commands/generate-impl.js:70:35)
at GenerateCommand.initialize (/data/data/com.termux/files/home/node_modules/@angular/cli/commands/generate-impl.js:16:54)
at GenerateCommand.validateAndRun (/data/data/com.termux/files/home/node_modules/@angular/cli/models/command.js:127:20)
at async Object.runCommand (/data/data/com.termux/files/home/node_modules/@angular/cli/models/command-runner.js:178:24)
at async default_1 (/data/data/com.termux/files/home/node_modules/@angular/cli/lib/cli/index.js:32:31)
请帮助解决此错误并修复此错误解决方案。
解决方案
- 创建项目后切换到您的项目文件夹或工作区。
- 跑
npm install
- 运行以下命令
ng generate component <componentName> //*for adding new component*
或ng generate service <serviceName> //*for adding new service*
推荐阅读
- python - Python KeyError:'C'
- ansible - 如何在 Ansiblized Kerberos KDC 设置中从命令行删除主密码?
- python - 如何在 python 中将数据文件转换为动画?
- python - ValueError:未转换的数据仍然存在:72
- google-chrome - TypeError:chrome.extension.getViews 不是函数
- c# - 如何在 Visual Studio 2019 的 Datagrid 视图中连接 MySQL DataTable 中的两列?
- javascript - 引导表排序/过滤不起作用
- python - Python中的元素操作基于多个条件比较元素与数组中的下一个元素
- python - .ppm 镜像镜像颠倒且质量低下
- sql - MyBatis 一次更新两个不同的 Oracle SQL 表