Angular-cli: Spec files in subdirs included in AOT compilation

Created on 12 Jan 2017  路  18Comments  路  Source: angular/angular-cli

OS?

Windows 10

Versions.

angular-cli: 1.0.0-beta.24
node: 6.9.1
os: win32 x64
@angular/common: 2.4.3
@angular/compiler: 2.4.3
@angular/core: 2.4.3
@angular/forms: 2.4.3
@angular/http: 2.4.3
@angular/platform-browser: 2.4.3
@angular/platform-browser-dynamic: 2.4.3
@angular/router: 3.4.3
@angular/compiler-cli: 2.4.3

Repro steps.

  1. ng init a new app.
  2. Create a subdir under src/app and cd into it
  3. ng g c test-comp
  4. Edit the test-comp.component.spec.ts file to include import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing'; (This is somewhat arbitrary - I just know this particular module breaks AOT.)
  5. run ng build -prod --aot

You'll get an error (see the log).

Note that if you do this directly under src/app you won't get an error, because the spec file is correctly excluded from the AOT build.

I believe the culprit is here: https://github.com/angular/angular-cli/blob/defc26935cad730dbdfb23c88ca229cba34f481d/packages/%40ngtools/webpack/src/plugin.ts#L124

The single-star replacement looks like it's clobbering the previous double-star replacement so you go from **/*\.spec\.ts after line 120 to (?:.*)/*\.spec\.ts after line 122 to (?:.(?:[^/]*))/(?:[^/]*)\.spec\.ts after line 124, when you probably actually want (?:.*)/(?:[^/]*)\.spec\.ts.

The log given by the failure.

ERROR in Error encountered resolving symbol values statically. Calling function 'NoOpAnimationDriver', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AnimationDriver.NOOP in C:/wsecug it/ng-cli-beta-24/node_modules/@angular/platform-browser/src/dom/animation_driver.d.ts, resolving symbol BrowserTestingModule in C:/wsecugit/ng-cli-beta-24/node_modules/@angular/platform-browser/testing/browser.d.ts, resolving symbol BrowserTestingModule in C:/wsecugit/n g-cli-beta-24/node_modules/@angular/platform-browser/testing/browser.d.ts

Most helpful comment

I think I might be running into this too. Things were working fine in beta.22-1 but upgrading to beta.26 started producing the exact error. It's still present with beta.30 and I haven't been able to figure out why test files are being loaded. Node_modules folder has been removed when upgrading each time.

All 18 comments

@mattdistefano can you try reproduce it on updated angular-cli? now it is 1.0.0-beta.25.5

Ah man you guys are killing me - just spent the afternoon upgrading from beta 23 to beta 24.

But yeah I'll check.

dup related #3928

@antonybudianto7 It looks similar but this issue is specifically re. spec files in subdirectories. Also the errors we're seeing look different.

@mattdistefano I used @angular/router/testing module, that's why it's different, but the fact is our spec file still get compiled :smile:

Can confirm this is present in beta 25.5 too:

angular-cli: 1.0.0-beta.25.5
node: 6.9.1
os: win32 x64
@angular/common: 2.4.3
@angular/compiler: 2.4.3
@angular/core: 2.4.3
@angular/forms: 2.4.3
@angular/http: 2.4.3
@angular/platform-browser: 2.4.3
@angular/platform-browser-dynamic: 2.4.3
@angular/router: 3.4.3
@angular/compiler-cli: 2.4.3

I think I was with the same issue, and after update to beta 25 it disappears.

This is fixed at the moment but I know some older versions of the CLI were more lenient with the dependency versions.

Make sure to follow the instructions in https://github.com/angular/angular-cli#updating-angular-cli, especially the bits where you delete your local node_modules.

@filipesilva Are you saying this is fixed in beta 26?

@mattdistefano probably even before that, but there might have been some old version of @ngtools/webpack sticking around.

Gotcha. Alright, I'll try again.

Hi, have got the same problem, i.e. one of my tests (.component.spec.ts) has an import to BrowserDynamicTestingModule in order to set the entryComponents property, and keeps failing with the error message mentioned above.

The problem is still there with the current version (angular-cli: 1.0.0-beta.26).

angular-cli: 1.0.0-beta.26 node: 7.1.0 os: win32 x64 @angular/common: 2.4.3 @angular/compiler: 2.4.3 @angular/core: 2.4.3 @angular/forms: 2.4.3 @angular/http: 2.4.3 @angular/platform-browser: 2.4.3 @angular/platform-browser-dynamic: 2.4.3 @angular/router: 3.4.3 @angular/compiler-cli: 2.4.3 @angular/platform-server: 2.4.3 @angular/tsc-wrapped: 0.5.1

@filipesilva I just confirmed this issue is still present in beta 26. See https://github.com/mattdistefano/ng-cli-beta26-spec-issue

I think I might be running into this too. Things were working fine in beta.22-1 but upgrading to beta.26 started producing the exact error. It's still present with beta.30 and I haven't been able to figure out why test files are being loaded. Node_modules folder has been removed when upgrading each time.

I have updated to cli 1.0.0-beta.32.3 and having the same issue too.

Will investigate.

Followed your repro and got this error:

ERROR in Error encountered resolving symbol values statically. Calling function 'NoOpAnimationDriver', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AnimationDriver.NOOP in D:/sandbox/master-project/node_modules/@angular/platform-browser/src/dom/animation_driver.d.ts, resolving symbol BrowserTestingModule in D:/sandbox/master-project/node_modules/@angular/platform-browser/testing/browser.d.ts, resolving symbol BrowserTestingModule in D:/sandbox/master-project/node_modules/@angular/platform-browser/testing/browser.d.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