[英]Adding @angular/pwa not working on angular CLI
I'm trying to run the command ng add @angular/pwa -- my project name so that I can implement service workers in my angular project but the error that I'm returned is "The add command requires to be run in an Angular project, but a project definition could not be found."我正在尝试运行命令 ng add @angular/pwa --我的项目名称,以便我可以在我的 angular 项目中实现服务工作者,但我返回的错误是“添加命令需要在 Angular 中运行项目,但找不到项目定义。” If anyone can shed some light on what I can do to get past this error it would be much appreciated.
如果有人能阐明我可以做些什么来克服这个错误,那将不胜感激。 I was upgrading from Angular CLI version 1.49.
我从 Angular CLI 版本 1.49 升级。 I have a feeling it has something to do with the angularcli.json file since the new version uses angular.json file.
我感觉它与 angularcli.json 文件有关,因为新版本使用 angular.json 文件。
This is also an exception when I try to use ng serve: Workspace needs to be loaded before it is used.当我尝试使用 ng serve 时,这也是一个例外:工作区需要在使用之前加载。 Error: Workspace needs to be loaded before it is used
错误:工作区在使用前需要加载
this is my version details:这是我的版本详细信息:
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 7.0.1
Node: 10.12.0
OS: darwin x64
Angular: 5.2.11
... animations, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic
... platform-server, router
Package Version
------------------------------------------------------
@angular-devkit/architect 0.10.1
@angular-devkit/core 0.3.2
@angular-devkit/schematics 7.0.1
@angular/cli 7.0.1
@ngtools/webpack 1.10.2
@schematics/angular 7.0.1
@schematics/update 0.10.1
rxjs 5.5.12
typescript 3.1.1
webpack 3.11.0
You are right regarding the new version using the updated angular.json
file. 您可以使用更新的
angular.json
文件使用新版本。 See the following links on updating the cli, they should help: Angular Cli Error: The serve command requires to be run in an Angular project, but a project definition could not be found and https://github.com/angular/angular-cli/issues/12215#issuecomment-433593036 请参阅以下有关更新cli的链接,它们将对您有所帮助: Angular Cli错误:serve命令需要在Angular项目中运行,但是找不到项目定义,并且https://github.com/angular/angular- cli / issues / 12215#issuecomment-433593036
In my case I did the following: 就我而言,我做了以下工作:
npm uninstall -g angular-cli
npm uninstall -g angular-cli
npm cache verify
npm cache verify
npm install -g @angular/cli@latest
npm install -g @angular/cli@latest
After installing the cli and generating your project, run the following inside the project directory where name
is the name of the app as defined inside the angular.json file: 安装cli并生成您的项目后,请在项目目录中运行以下命令,其中
name
是在angular.json文件中定义的应用程序名称:
ng add @angular/pwa --project name
It is important to note that name
is the name of the project as listed inside the angular.json
file. 重要的是要注意
name
是在angular.json
文件中列出的项目的名称。 Inside that file you should find a directive like this: "defaultProject": "app",
. 在该文件中,您应该找到类似以下的指令:
"defaultProject": "app",
So in my case it will be: 所以对于我来说,它将是:
ng add @angular/pwa --project app
For existing projects, ng generate won't be the best solution.对于现有项目,ng generate 不会是最好的解决方案。 Check the angular.json in your project folder.
检查项目文件夹中的 angular.json。 "projects" key may have a project name.
“projects”键可能有一个项目名称。 Underneath that you may find configurations for multiple commands.
在其下方,您可能会找到多个命令的配置。 Try with that project name.
尝试使用该项目名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.