Universal: npm run prerender does not create the ngsw-worker.js, ngsw.json files

Created on 13 Feb 2020  路  13Comments  路  Source: angular/universal

馃悶 Bug report

What modules are related to this issue?

  • [ ] aspnetcore-engine
  • [x] builders
  • [ ] common
  • [x] express-engine
  • [ ] hapi-engine
  • [ ] module-map-ngfactory-loader

Is this a regression?

I don't know, possibly but before I used universal angular with module-map-ngfactory-loader and exported the files that I mentioned.

Description

npm run prerender does not create the ngsw-worker.js, ngsw.json files.
create the application but only these two ngsw-worker.js, ngsw.json files would be missing.

馃敩 Minimal Reproduction

npm run prerender

Hash: ef705016a62ee6d8132b
Time: 26852ms
Built at: 13/02/2020 12:02:42
  Asset      Size  Chunks                    Chunk Names
main.js  2.85 MiB       0  [emitted]  [big]  main
Entrypoint main [big] = main.js
chunk    {0} main.js (main) 5.85 MiB [entry] [rendered]
Generating ES5 bundles for differential loading...
ES5 bundle generation complete.

chunk {3} polyfills-es5.6e2f468dea03dd10e7eb.js, polyfills-es5.6e2f468dea03dd10e7eb.js.map (polyfills-es5) 127 kB [initial] [rendered]
chunk {2} polyfills-es2015.db39b23daa8851ccf344.js, polyfills-es2015.db39b23daa8851ccf344.js.map (polyfills) 35.7 kB [initial] [rendered]
chunk {1} main-es2015.dc112d754bfac23b83ec.js, main-es2015.dc112d754bfac23b83ec.js.map (main) 27.2 kB [initial] [rendered]
chunk {1} main-es5.dc112d754bfac23b83ec.js, main-es5.dc112d754bfac23b83ec.js.map (main) 27.3 kB [initial] [rendered]
chunk {0} runtime-es2015.0811dcefd377500b5b1a.js, runtime-es2015.0811dcefd377500b5b1a.js.map (runtime) 1.51 kB [entry] [rendered]
chunk {0} runtime-es5.0811dcefd377500b5b1a.js, runtime-es5.0811dcefd377500b5b1a.js.map (runtime) 1.51 kB [entry] [rendered]
chunk {5} vendor-es2015.e73c2103cca588ed7f1a.js, vendor-es2015.e73c2103cca588ed7f1a.js.map (vendor) 227 kB [initial] [rendered]
chunk {5} vendor-es5.e73c2103cca588ed7f1a.js, vendor-es5.e73c2103cca588ed7f1a.js.map (vendor) 276 kB [initial] [rendered]
chunk {4} styles.68693795d6011f90ac29.css, styles.68693795d6011f90ac29.css.map (styles) 0 bytes [initial] [rendered]
Date: 2020-02-13T17:02:44.110Z - Hash: 65d4add55f562df7782d - Time: 29964ms
Prerendering 1 route(s) to /Users/edwingarcia/Desktop/Angular-Universal/AppSemillasV2/dist/AppSemillasV2/browser
CREATE /Users/edwingarcia/Desktop/Angular-Universal/AppSemillasV2/dist/AppSemillasV2/browser/index.html (27901 bytes)

Captura de Pantalla 2020-02-13 a la(s) 11 59 59 a 聽m

GitHub repository with the reproduction of the issue:

https://github.com/EdwinFdoGarcia/npm-run-prerender-does-not-create-the-ngsw-worker.js-ngsw.json-files

Issues that don't have enough info and can't be reproduced will be closed.

馃實 Your Environment




Angular CLI: 9.0.1
Node: 10.18.1
OS: darwin x64

Angular: 9.0.1
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... platform-server, router, service-worker
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.1
@angular-devkit/build-angular     0.900.1
@angular-devkit/build-optimizer   0.900.1
@angular-devkit/build-webpack     0.900.1
@angular-devkit/core              9.0.1
@angular-devkit/schematics        9.0.1
@ngtools/webpack                  9.0.1
@nguniversal/builders             9.0.0
@nguniversal/common               9.0.0
@nguniversal/express-engine       9.0.0
@schematics/angular               9.0.1
@schematics/update                0.900.1
rxjs                              6.5.4
typescript                        3.7.5
webpack                           4.41.2`

required builders hours feature

Most helpful comment

@geometricpanda If you wish to force prerender to create service worker you can open "node_modules\@nguniversal\builders\src\prerender\index.js" and set
serviceWorker: true, line 42

I don't know why angular.json configuration is overridden and commentary added:

todo: handle service worker augmentation

All 13 comments

This might be the same problem as my issue https://github.com/angular/universal/issues/1509#issue-565426201

@scurk1415, not quite as this feature is not available yet.

Hi, the issue https://github.com/angular/angular-cli/issues/17021#issue-565426201 got a milestone assigned, but this issue doesn't.

Does this mean the other issue will also fix the problem that prerender doesn't generate the ngsw-worker.js?

@alan-agius4, do you know if there's any plan to look into this please?

@geometricpanda, will try to look at this in the coming weeks.

Unless someone else wants to pick it up.

@alan-agius4 i'd love to but honestly I wouldnt know where to start right now

@geometricpanda If you wish to force prerender to create service worker you can open "node_modules\@nguniversal\builders\src\prerender\index.js" and set
serviceWorker: true, line 42

I don't know why angular.json configuration is overridden and commentary added:

todo: handle service worker augmentation

Until it's fixed, I made this awful temporary workaround for the folks running this on CI:
"enable-service-worker-hack": "sed -i -e \"s/serviceWorker: false/serviceWorker: true/g\" ./node_modules/@nguniversal/builders/src/prerender/index.js",

Then, npm run enable-service-worker-hack && ng run myproject:prerender

Obviously this is fragile and a really bad idea, be sure to lock down your versions. Another "hack' is to just run a normal production build before the current one and copy the ngsw-worker.js + ngsw.json from this build into the prerendered one.

Does yours project keep offline with this prerender?

I don't know when it will be fixed, so I created a custom builder that will generate the files needed for service-worker.

hsuanxyz/additional-service-worker-builder

You can use it like this:

$ ng run <project_name>:prerender
$ ng run <project_name>:service-work

@alan-agius4 do we have an estimated time of when this will be fixed? thanks!!

@alan-agius4 Is there any problem when serviceWorker: false has been removed from prerender/index.ts?

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._

Was this page helpful?
0 / 5 - 0 ratings