Skip to content

ng serve compiles sucessfully even if some assets are missing #6689

Closed
@aerojas

Description

@aerojas

Bug Report or Feature Request (mark with an x)

- [ x ] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.1.0
node: 7.8.0
os: win32 x64 //(Windows 7)
@angular/animations: 4.1.3
@angular/common: 4.1.3
@angular/compiler: 4.1.3
@angular/core: 4.1.3
@angular/forms: 4.1.3
@angular/http: 4.1.3
@angular/platform-browser: 4.1.3
@angular/platform-browser-dynamic: 4.1.3
@angular/platform-server: 4.1.3
@angular/router: 4.1.3
@angular/cli: 1.1.0
@angular/compiler-cli: 4.1.3

Repro steps.

  • In angular-cli.json, add a non-existant file in the assets array.

The log given by the failure.

webpack: Compiled successfully when doing ng serve

Desired functionality.

I expected some sort of "file not found" error to appear.

Mention any other details that might be useful.

I'm trying to use a JavaScript file as a Service Worker. I cannot put it in /assets/ folder because that would change the scope of the SW to /assets/ instead of / (I tried doing that, and I had to use serviceWorker.register('/assets/sw.js') or Angular couldn't find the file). I'd like to put the file on the root, so I can have a root scope for my SW.

Working with the angular-cli.json file I realized there is no way of testing if the file I'm referencing to is recognized somehow by Angular CLI when doing ng serve so I tried to add a non-existant file in order to purposefully generate an error while compiling, which did not happen. So I have no way of checking if my asset references are correct or not. I tried doing <script src="sw.js"></script> at the index.html file and adding a console.log in order to check if the file is loaded or not. The sw.js file is in the src folder, and some relevant lines from the angular-cli.json file are the following:

"apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "sws.js", //Non-existant file! It should be sw.js instead
        "favicon.ico"
      ],
      "index": "index.html",

And the SW registration script in my index.html:

<script>
      if('serviceWorker' in navigator){
      navigator.serviceWorker
        .register('/sw.js')
        .then(() => {
          console.log("Service Worker Registered. "); 
        })
        .catch((err) => {
          console.log("Service Worker failed to register: " + err);
        })
      } else {
        console.log("Service what?");
      }
</script>

So I cannot find a way to include sw.js as an asset. I heard of Angular Mobile, but I want to start with something simpler first.

I used as reference to implement my SW the following:

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: @angular-devkit/build-angularfeatureIssue that requests a new featurefreq1: lowOnly reported by a handful of users who observe it rarelyseverity2: inconvenient

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions