angular-cli: Angular-cli doesn't watch for ALL files correctly.

Bug Report or Feature Request (mark with an x)

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

Versions.

@angular/cli: 1.4.2 node: 7.5.0 os: win32 x64 @angular/common: 4.4.4 @angular/compiler: 4.4.4 @angular/core: 4.4.4 @angular/forms: 4.4.4 @angular/http: 4.4.4 @angular/platform-browser: 4.4.4 @angular/platform-browser-dynamic: 4.4.4 @angular/router: 4.4.4 @angular/cli: 1.4.2 @angular/compiler-cli: 4.4.4 typescript: 2.2.2

Repro steps.

watch bug.zip

  1. npm install
  2. ng serve
  3. change anything in src/app/store/application-state.ts (it is linked in component, which is used in app.module.ts) and SAVE = NO REBUILD
  4. Change (example) from storeData: string; to storeData: boolean; and RE-SAVE anything else where the watch is correctly watching = application successfully built, but it SHOULD NOT, because there is assignment: store.subscribe(x=> x.storeData = “pepa”) but type of storeData has been changed to boolean…

Desired functionality.

It should watch for all files correctly

Mention any other details that might be useful.

  • I have tried to change typescript to 2.4.0+ (because of breaking change in CHANGELOG) = NOT WORKING

  • i have tried to update globally angular-cli(1.4.5) and create new APP via ng new = with latest dependencies = NOT WORKING

BTW even with latest Angular-cli, typescript version in dev-dependencies is “~2.3.3” despite your required version in CHANGELOG

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 21 (11 by maintainers)

Commits related to this issue

Most upvoted comments

After investigating, you’re correct in your assumption that it’s not the same issue.

The problem is 3 fold:

  1. TypeScript discards type information, and since you’re only importing types that file will be discarded from the compilation output;
  2. Since it’s discarded from the output, Webpack does not know about the dependency between your file and the TypeScript that includes the type.
  3. We rely on Webpack’s dependency graph to actually know if something needs rebuilding.

The only point where we actually have control is point 3 and we should look at dependencies inside TypeScript and tell webpack about TS’s dependency graph. I’ll come up with a fix soon.

Ok so I’m looking at the file online in https://unpkg.com/@ngtools/webpack@1.7.3/src/loader.js. You’re right, it’s quite different. We published stable (1.7.3) but also the beta (1.8.0-beta.4), and a lot of code in that PR is only for the beta.

What you want to change is:

// from
            _getImports(refactor, compilerOptions, plugin.compilerHost, plugin.moduleResolutionCache)
                .forEach((importString) => this.addDependency(importString));
// to
            _getImports(refactor, compilerOptions, plugin.compilerHost, plugin.moduleResolutionCache)
                .forEach((dep) => this.addDependency(dep.replace(/\//g, path.sep)));

This should be enough to test.

I’ll take a look and try to get some numbers to benchmark. Thank you.