Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PWA ng-add schematic does not work if bootstrapApplication is used (standalone) #23316

Closed
2 of 15 tasks
ngfelixl opened this issue Jun 8, 2022 · 9 comments
Closed
2 of 15 tasks
Labels
area: @schematics/angular feature: in backlog Feature request for which voting has completed and is now in the backlog feature Issue that requests a new feature

Comments

@ngfelixl
Copy link

ngfelixl commented Jun 8, 2022

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • extract-i18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

In the previous version of Angular (13) there was no support for standalone components.

Description

The ng-add schematic for the package @angular/pwa does not work if the app bootstraps using bootstrapApplication from @angular/platform-browser instead of the good old bootstrapModule function in the apps main.ts file.

🔬 Minimal Reproduction

1.) Create a new Angular app with version 14:

npx @angular/cli@14 new pwa-test-app
cd pwa-test-app

2.) Remove the app.module.ts file and change the app.component.ts decorator to

@Component({
  standalone: true,
  selector: 'app-root',
  imports: [CommonModule],
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})

3.) Change the main.ts file to

import { enableProdMode } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
import { environment } from './environments/environment';

if (environment.production) {
  enableProdMode();
}

bootstrapApplication(AppComponent);

4.) ng-add @angular/pwa

Run

npx ng add @angular/pwa

Answer yes to the following terminal output

ℹ Using package manager: npm
✔ Found compatible package version: @angular/pwa@14.0.0.
✔ Package information loaded.

The package @angular/pwa@14.0.0 will be installed and executed.
Would you like to proceed? (Y/n) y

🔥 Exception or Error


Bootstrap call not found

🌍 Your Environment


Angular CLI: 14.0.0
Node: 16.14.0
Package Manager: npm 8.3.1 
OS: darwin x64

Angular: 14.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1400.0
@angular-devkit/build-angular   14.0.0
@angular-devkit/core            14.0.0
@angular-devkit/schematics      14.0.0
@schematics/angular             14.0.0
rxjs                            7.5.5
typescript                      4.7.3

I would be very happy to support you with this issue if some guidance is provided.

@alan-agius4 alan-agius4 added area: @angular/pwa type: bug/fix freq1: low Only reported by a handful of users who observe it rarely severity3: broken labels Jun 8, 2022
@ngfelixl
Copy link
Author

ngfelixl commented Jun 8, 2022

Instead of only looking for bootstrapModule, it should also search for bootstrapApplication. If the first one is found, nothing to be changed. If the second one is found it should add it to the providers array as it does for modules:

import { importProvidersFrom } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
// [...]

bootstrapApplication(AppComponent, {
  providers: [
    importProvidersFrom(
      ServiceWorkerModule.register('ngsw-worker.js', {
        enabled: environment.production,
        // Register the ServiceWorker as soon as the application is stable
        // or after 30 seconds (whichever comes first).
        registrationStrategy: 'registerWhenStable:30000',
      })
    ),
  ],
});

This works fine for my app. For everyone looking for a solution: As a workaround, you can setup a temporary NgModule AppModule and use the bootstrapModule function. This way the schematic succeeds. Once it's done, change it back to bootstrapApplication, remove the NgModule and use the above snippet to register the ServiceWorker.

@clydin
Copy link
Member

clydin commented Jun 8, 2022

Developer Preview APIs currently do not have full tooling support. Additional tooling support for Standalone Components will be added in the 14.x timeframe as the APIs are stabilized.

@ngfelixl
Copy link
Author

ngfelixl commented Jun 8, 2022

I see! Thanks for the clarification 😊

@sefatanam
Copy link

sefatanam commented Aug 8, 2022

I faced same issue today, detail I described here https://stackoverflow.com/questions/73274104/ng-add-angular-pwa-bootstrap-call-not-found-in-angular-standalone-project. Look forward to it ....

@alan-agius4 alan-agius4 changed the title PWA ng-add schematic does not work if bootstrapApplication is used PWA ng-add schematic does not work if bootstrapApplication is used (standaloine) Oct 11, 2022
@alan-agius4 alan-agius4 changed the title PWA ng-add schematic does not work if bootstrapApplication is used (standaloine) PWA ng-add schematic does not work if bootstrapApplication is used (standalone) Oct 11, 2022
@alan-agius4 alan-agius4 added feature Issue that requests a new feature area: @schematics/angular feature: in backlog Feature request for which voting has completed and is now in the backlog and removed type: bug/fix freq1: low Only reported by a handful of users who observe it rarely severity3: broken area: @angular/pwa labels Oct 11, 2022
@DDD-fx
Copy link

DDD-fx commented Jan 28, 2023

Still waiting for the fix

@Yutsa
Copy link

Yutsa commented Apr 4, 2023

Today I tried to add angular-pwa to my project running Angular v15 but unfortunately it still does not work with bootstrapApplication :

The package @angular/pwa@15.2.4 will be installed and executed.
Would you like to proceed? Yes
✔ Packages successfully installed.
Bootstrap call not found

This is not a preview feature anymore right ?

@alan-agius4
Copy link
Collaborator

This is available in version 16 which is currently in prerelease.

@alan-agius4
Copy link
Collaborator

Closing as per above.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: @schematics/angular feature: in backlog Feature request for which voting has completed and is now in the backlog feature Issue that requests a new feature
Projects
None yet
Development

No branches or pull requests

6 participants