question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Service Worker with ng build --prod error

See original GitHub issue
> ng build --prod
Date: 2017-12-06T21:13:24.157Z
Hash: 3fb405a90a2041f6cbd3
Time: 116738ms
chunk {0} main.ff8fe03a5f3f52a1a90b.bundle.js (main) 1.47 MB [initial] [rendered]
chunk {1} polyfills.17a4fcb6e694c489ccd3.bundle.js (polyfills) 136 kB [initial] [rendered]
chunk {2} styles.5d12b9488551c2f2986e.bundle.css (styles) 31 kB [initial] [rendered]
chunk {3} inline.af36f1bf44c2ee9116c0.bundle.js (inline) 1.45 kB [entry] [rendered]

An error occured during the build:
TypeError: Cannot read property 'files' of undefined
    at Generator.<anonymous> (myapp/node_modules/@angular/service-worker/bundles/service-worker-config.umd.js:255:85)
    at step (myapp/node_modules/@angular/service-worker/bundles/service-worker-config.umd.js:71:23)
    at Object.next (myapp/node_modules/@angular/service-worker/bundles/service-worker-config.umd.js:52:53)
    at myapp/node_modules/@angular/service-worker/bundles/service-worker-config.umd.js:45:71
    at new Promise (<anonymous>)
    at __awaiter (myapp/node_modules/@angular/service-worker/bundles/service-worker-config.umd.js:41:12)
    at myapp/node_modules/@angular/service-worker/bundles/service-worker-config.umd.js:249:108
    at Array.map (<anonymous>)
    at Generator.<anonymous> (myapp/node_modules/@angular/service-worker/bundles/service-worker-config.umd.js:249:78)
    at step (myapp/node_modules/@angular/service-worker/bundles/service-worker-config.umd.js:71:23)
    at Object.next (myapp/node_modules/@angular/service-worker/bundles/service-worker-config.umd.js:52:53)
    at myapp/node_modules/@angular/service-worker/bundles/service-worker-config.umd.js:45:71
    at new Promise (<anonymous>)
    at __awaiter (myapp/node_modules/@angular/service-worker/bundles/service-worker-config.umd.js:41:12)
    at Generator.processAssetGroups (myapp/node_modules/@angular/service-worker/bundles/service-worker-config.umd.js:244:16)
    at Generator.<anonymous> (myapp/node_modules/@angular/service-worker/bundles/service-worker-config.umd.js:224:51)
Cannot read property 'files' of undefined

> ng -v

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

Angular CLI: 1.6.0-rc.2
Node: 8.9.1
OS: darwin x64
Angular: 5.0.5
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router
... service-worker

@angular/cli: 1.6.0-rc.2
@angular-devkit/build-optimizer: 0.0.34
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.39
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.0-rc.2
@schematics/angular: 0.1.9
typescript: 2.6.2
webpack: 3.10.0


If I set "serviceWorker": true in angular-cli.json I get the error above.

If I run “ng build” without --prod it works fine however my bundle size goes to 13Mb. If I set the serviceWorker to false it builds OK and my bundle is only 3Mb, however I have no PWA capability. It’d be great to have a small bundle + PWA goodness.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
awsedcommented, Dec 12, 2017

Sorry, just realized my own stupidity. The JSON was all wrong, after fixing it I can build fine:

{
  "index": "/index.html",
  "assetGroups": [{
    "name": "app",
    "installMode": "prefetch",
    "resources": {
      "files": [
        "/favicon.ico",
        "/index.html"
      ],
      "versionedFiles": [
        "/*.bundle.css",
        "/*.bundle.js",
        "/*.chunk.js"
      ]
    }
  }, {
    "name": "assets",
    "installMode": "lazy",
    "updateMode": "prefetch",
    "resources": {
      "files": [
        "/assets/**"
      ],
      "urls": [
        "https://fonts.googleapis.com/**",
        "https://fonts.gstatic.com/**",
        "https://code.ionicframework.com/**"
      ]
    }
  }],
  "dataGroups": [
    {
      "name": "api",
      "urls": ["/chat"],
      "cacheConfig": {
        "strategy": "freshness",
        "maxSize": 50,
        "maxAge": "30m",
        "timeout": "5s"
      }
    }
  ]
}
0reactions
angular-automatic-lock-bot[bot]commented, Sep 7, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular service worker not found/registered error when ...
If I run ng serve --prod the app runs successfully but I get a console error TypeError: Failed to register a ServiceWorker: A...
Read more >
How To Run The Angular Service Worker In Production Mode
In FireFox I'm getting a Corripted Content Error: The site at http://localhost:8080/ has experienced a network protocol violation that cannot be repaired.
Read more >
Service worker in production - Angular
The service worker either returns a cached response or sends the request to the server, depending on the state and configuration of the...
Read more >
Service Workers & Angular - Martin Džejky Jakubik
Now rebuild the application ( ng build --prod ) and serve it again. It almost works... Except that I made a mistake which...
Read more >
How to Use Ng Serve with Service Worker Support - Bitovi
To see your changes and test your service worker before version 14.2, you need to build your application with: ng build --prod.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found