Skip to content

Generated output in ngsw.json is wrong #23422

Closed as not planned
Closed as not planned

Description

@zizizi17

I'm submitting a...


[x] Bug report 
[ ] Feature request

Current behavior

When run the build script with the inline argument of --base-href /current/ and in the ngsw.json file use the absolute path for the files, it produces the path /current/index.html in the built ngsw.json. Using of the relative path in the ngsw.json does not help.

Expected behavior

Either using the relative path in the ngsw.json or generating the output due to the --base-href value.

Environment


Angular version: 5.0.0
@angular/service-worker: 5.2.10

Browser:
- [x] Chrome (desktop) version 65
For Tooling issues:
- Node version: 8.9.4
- Platform: Windows

Activity

  1. added this to the needsTriage milestone on Apr 17, 2018
  2. gkalpak commented on Apr 18, 2018

    @gkalpak
    Member

    Yeah, I've been thinking about this one myself (if I understand correctly what you are saying).
    I would expect that baseHref would only be prepended to relative paths, not absolute paths.

    E.g.:

    // ngsw-config.json
    {
      ...
      "assetGroups": [{
        ...
        "resources": {
          "files": [
            "relative/path.html",
            "/absolute/path.html",
          ],
        }
      }]
    }

    Expected (with baseHref = /foo/):

    // ngsw.json
    {
      ...
      "assetGroups": [{
        ...
        "urls": [
          "/foo/relative/path.html",
          "/absolute/path.html",
        ],
      }]
    }

    Actual (with baseHref = /foo/):

    // ngsw.json
    {
      ...
      "assetGroups": [{
        ...
        "urls": [
          "/foo/relative/path.html",
          "/foo/absolute/path.html",
        ],
      }]
    }

    cc @alxhub

  3. gkalpak commented on Apr 18, 2018

    @gkalpak
    Member

    Oh...wait. Actually, these are file paths (not urls). So, you can't really know whether the urls will be relative or absolute. Asset-group urls are treated correctly (only prepending baseHref to relative urls).

    It might be a useful feature though, to be able to indicate whether a file requires baseHref to be prepended or not.

  4. zizizi17 commented on Apr 18, 2018

    @zizizi17
    Author

    But in the config ngsw.json you only absolute paths work. Whern I use the relative path ./index.html, the output is /baseHref/index.html. And it breaks the structure.

  5. modified the milestones: needsTriage, Backlog on Apr 24, 2018
  6. gkalpak commented on May 25, 2020

    @gkalpak
    Member

    For future reference:
    The ngsw.json manifest includes some paths to files in the project's output directory. For example, assetGroups -> <group-name> -> resources -> files or index. It is not clear what effect --baseHref should have on those.

    • On one hand, it might seem reasonable to prepend the base href to relative paths (e.g. foo/file) and leave absolute paths (e.g. /foo/file) alone.
    • On the other hand, these are file paths (not URLs) and they are interpreted with the project's output directory as root, so both relative and absolute paths refer to the same files.

    Changing the behavior of --baseHref to only affect relative paths might give people an option to use either behavior (i.e. they could use relative paths if they want them to be prepended with the base href and absolute paths otherwise), but that would (a) be a breaking change and (b) lead to unexpected/hard-to-debug changes in behavior from seemingly innocent change.

    We should look into how we can accomodate all usecases with as predictable a behavior as possible (and document these things in detail).

    Note that the CLI, in addition to --baseHref also has a --deployUrl option, but it is not clear what its behavior is and whether its use is encouraged (e.g. I know there have been discussions about removing it).

  7. added
    P4A relatively minor issue that is not relevant to core functions
    and removed on Oct 1, 2020
  8. JeanMeche commented on Aug 29, 2025

    @JeanMeche
    Member

    With #63364 we've announced that the service-worker package in now in maintenance mode and will not receive feature PRs and feature requests.

    The message is also visible here: https://angular.dev/ecosystem/service-workers

  9. angular-automatic-lock-bot commented on Sep 29, 2025

    @angular-automatic-lock-bot

    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.

  10. locked and limited conversation to collaborators on Sep 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions