gpt4 book ai didi

angular - 添加 @angular/pwa 不适用于 Angular CLI

转载 作者:太空狗 更新时间:2023-10-29 17:58:17 26 4
gpt4 key购买 nike

我正在尝试运行命令 ng add @angular/pwa --my project name 以便我可以在我的 angular 项目中实现服务 worker ,但返回的错误是“添加命令需要在 Angular 项目中运行,但找不到项目定义。”如果有人能阐明我可以做些什么来克服这个错误,我将不胜感激。我正在从 Angular CLI 版本 1.49 升级。我觉得它与 angularcli.json 文件有关,因为新版本使用 angular.json 文件。

当我尝试使用 ng serve 时,这也是一个异常(exception):Workspace 在使用前需要加载。错误:工作区在使用前需要加载

这是我的版本详情:

    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/


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

最佳答案

关于使用更新的 angular.json 文件的新版本,您是正确的。请参阅以下有关更新 cli 的链接,它们应该会有所帮助:Angular Cli Error: The serve command requires to be run in an Angular project, but a project definition could not be foundhttps://github.com/angular/angular-cli/issues/12215#issuecomment-433593036

在我的例子中,我做了以下事情:

  1. 卸载 cli:npm uninstall -g angular-cli
  2. 清除 npm 缓存:npm cache verify
  3. 重新安装 angular cli:npm install -g @angular/cli@latest

安装 cli 并生成项目后,在项目目录中运行以下命令,其中 name 是在 angular.json 文件中定义的应用程序名称:

ng add @angular/pwa --project name

请务必注意,nameangular.json 文件中列出的项目名称。在该文件中,您应该找到如下指令:"defaultProject": "app",。所以就我而言,它将是:

ng add @angular/pwa --project app

关于angular - 添加 @angular/pwa 不适用于 Angular CLI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52885558/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com