File tree 2 files changed +11
-4
lines changed
lib/core/common-behaviors
2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,9 @@ export class MatCommonModule {
37
37
/** Reference to the global `document` object. */
38
38
private _document = typeof document === 'object' && document ? document : null ;
39
39
40
+ /** Reference to the global 'window' object. */
41
+ private _window = typeof window === 'object' && window ? window : null ;
42
+
40
43
constructor ( @Optional ( ) @Inject ( MATERIAL_SANITY_CHECKS ) private _sanityChecksEnabled : boolean ) {
41
44
if ( this . _areChecksEnabled ( ) && ! this . _hasDoneGlobalChecks ) {
42
45
this . _checkDoctypeIsDefined ( ) ;
@@ -52,7 +55,7 @@ export class MatCommonModule {
52
55
53
56
/** Whether the code is running in tests. */
54
57
private _isTestEnv ( ) {
55
- return window [ '__karma__' ] || window [ 'jasmine' ] ;
58
+ return this . _window && ( this . _window [ '__karma__' ] || this . _window [ 'jasmine' ] ) ;
56
59
}
57
60
58
61
private _checkDoctypeIsDefined ( ) : void {
@@ -90,7 +93,11 @@ export class MatCommonModule {
90
93
91
94
/** Checks whether HammerJS is available. */
92
95
_checkHammerIsAvailable ( ) : void {
93
- if ( this . _areChecksEnabled ( ) && ! this . _hasCheckedHammer && ! window [ 'Hammer' ] ) {
96
+ if ( this . _hasCheckedHammer || ! this . _window ) {
97
+ return ;
98
+ }
99
+
100
+ if ( this . _areChecksEnabled ( ) && ! this . _window [ 'Hammer' ] ) {
94
101
console . warn (
95
102
'Could not find HammerJS. Certain Angular Material components may not work correctly.' ) ;
96
103
}
Original file line number Diff line number Diff line change 1
- import { enableProdMode } from '@angular/core' ;
2
1
import { renderModuleFactory } from '@angular/platform-server' ;
3
2
import { readFileSync , writeFileSync } from 'fs-extra' ;
4
3
import { log } from 'gulp-util' ;
@@ -7,7 +6,8 @@ import 'reflect-metadata';
7
6
import 'zone.js' ;
8
7
import { KitchenSinkServerModuleNgFactory } from './kitchen-sink/kitchen-sink.ngfactory' ;
9
8
10
- enableProdMode ( ) ;
9
+ // Do not enable production mode, because otherwise the `MatCommonModule` won't execute
10
+ // the browser related checks that could cause NodeJS issues.
11
11
12
12
const result = renderModuleFactory ( KitchenSinkServerModuleNgFactory , {
13
13
document : readFileSync ( join ( __dirname , 'index.html' ) , 'utf-8' )
You can’t perform that action at this time.
0 commit comments