代码之家  ›  专栏  ›  技术社区  ›  Farhan Islam

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

  •  4
  • Farhan Islam  · 技术社区  · 6 年前

    我正在运行命令ng add@angular/pwa-- 我的项目名称

    当我尝试使用ng serve时,这也是一个例外: 工作区需要在使用前加载。 错误:工作区需要在使用前加载

        / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
       / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
      / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
     /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                    |___/
    
    
    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
    
    1 回复  |  直到 6 年前
        1
  •  3
  •   l3vi_14    6 年前

    关于使用更新的 angular.json Angular Cli Error: The serve command requires to be run in an Angular project, but a project definition could not be found https://github.com/angular/angular-cli/issues/12215#issuecomment-433593036

    在我的情况下,我做了以下工作:

    1. npm uninstall -g angular-cli
    2. 清除npm缓存: npm cache verify
    3. npm install -g @angular/cli@latest

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

    ng add @angular/pwa --project name

    值得注意的是 名称 文件。在该文件中,您应该可以找到如下指令: "defaultProject": "app", . 所以在我的情况下是:

    ng add @angular/pwa --project app