Skip to content

Commit 6087ab6

Browse files
committed
Add more detailed error message around platform creation failure
1 parent cb50fd8 commit 6087ab6

File tree

10 files changed

+36
-27
lines changed

10 files changed

+36
-27
lines changed

examples/cli/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
"@angular/platform-browser-dynamic": "4.2.2",
2525
"@angular/router": "4.2.2",
2626
"@angular/tsc-wrapped": "4.2.2",
27+
"@types/node": "^6.0.60",
28+
"codelyzer": "^2.0.0",
2729
"angular-ssr": "latest",
2830
"classlist.js": "^1.1.20150312",
2931
"core-js": "^2.4.1",
@@ -32,15 +34,13 @@
3234
"live-server": "^1.2.0",
3335
"preboot": "^4.5.2",
3436
"reflect-metadata": "^0.1.10",
35-
"rxjs": "^5.1.0",
37+
"rxjs": "^5.4.1",
38+
"ts-node": "^2.0.0",
39+
"tslint": "^4.5.0",
40+
"typescript": "2.3.2",
3641
"web-animations-js": "^2.2.2",
3742
"zone.js": "^0.8.4"
3843
},
3944
"devDependencies": {
40-
"@types/node": "~6.0.60",
41-
"codelyzer": "~2.0.0",
42-
"ts-node": "~2.0.0",
43-
"tslint": "~4.5.0",
44-
"typescript": "~2.2.0"
4545
}
4646
}

examples/demand-express/app/blog/service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {Blog} from './model';
1010
export class BlogService {
1111
constructor(private http: Http) {}
1212

13-
load(locale: string): Observable<ArrayLike<Blog>> {
13+
load(locale: string): Observable<Array<Blog>> {
1414
return this.http.get('https://raw.githubusercontent.com/clbond/angular-ssr/master/examples/demand-express/mock-content.json').map(r => r.json()).map(c => c[locale]);
1515
}
16-
}
16+
}

examples/demand-express/app/locale/service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class LocaleService {
1616
if (locale) {
1717
this.update(locale);
1818
}
19-
return this.subject;
19+
return Observable.from(this.subject);
2020
}
2121

2222
private update(value: string) {

examples/demand-express/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"to-string-loader": "^1.1.5",
5454
"ts-loader": "^2.0.3",
5555
"ts-node": "^3.0.2",
56-
"typescript": "^2.2.1",
56+
"typescript": "2.3.2",
5757
"webpack": "^2.2.1",
5858
"zone.js": "^0.8.5"
5959
}

examples/demand-express/server/http.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const configure = (http: express.Application): void => {
1515
};
1616

1717
export const listen = (http: express.Application): Promise<number> => {
18-
const port = process.env.PORT || 8080;
18+
const port: number = process.env.PORT ? parseInt(process.env.PORT, 10) : 8080;
1919

2020
return new Promise<number>((resolve, reject) => {
2121
http.listen(port, err => {
@@ -35,4 +35,4 @@ export const absoluteUri = (request: express.Request): string => {
3535
host: request.get('host'),
3636
pathname: request.originalUrl
3737
});
38-
};
38+
};

package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-ssr",
3-
"version": "0.10.23",
3+
"version": "0.10.29",
44
"description": "Angular server-side rendering implementation",
55
"main": "build/index.js",
66
"typings": "build/index.d.ts",
@@ -66,9 +66,9 @@
6666
"@angular/tsc-wrapped": ">=4.2.2 <5.0.0",
6767
"@angular/service-worker": ">=1.0.0 || >=1.0.0-beta.8",
6868
"reflect-metadata": ">=0.1.10",
69-
"rxjs": ">=5.0.1",
69+
"rxjs": "^5.4.1",
7070
"zone.js": ">=0.8",
71-
"typescript": ">=2.3.2",
71+
"typescript": "~2.3.2",
7272
"webpack": ">=2.3.0"
7373
},
7474
"dependencies": {
@@ -88,10 +88,11 @@
8888
"npm-run-all": "^4.0.2",
8989
"preboot": "^4.5.2",
9090
"rimraf": "2.5.4",
91-
"rxjs": ">=5.0.1",
91+
"rxjs": "^5.4.1",
9292
"scoped-logger": "^0.0.19",
9393
"source-map-support": ">=0.1.0",
9494
"symbol-observable": "^1.0.4",
95+
"typescript": "2.3.2",
9596
"xhr2": "^0.1.4"
9697
},
9798
"devDependencies": {
@@ -114,7 +115,6 @@
114115
"reflect-metadata": ">=0.1.10",
115116
"ts-jest": "^20.0.4",
116117
"tslint": "4.4.2",
117-
"typescript": ">=2.3.2",
118118
"webpack": ">=2.4.1",
119119
"zone.js": ">=0.8.9"
120120
},
@@ -147,7 +147,9 @@
147147
],
148148
"verbose": true,
149149
"cacheDirectory": ".jest-cache",
150-
"coveragePathIgnorePatterns": [".*\\.(shim\\.ngstyle|ngfactory)\\.ts"],
150+
"coveragePathIgnorePatterns": [
151+
".*\\.(shim\\.ngstyle|ngfactory)\\.ts"
152+
],
151153
"globals": {
152154
"__TS_CONFIG__": "tsconfig.json"
153155
}

source/application/builder/impl/application.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class ApplicationImpl<V, M> implements Application<V> {
8787

8888
Promise.all(promises).then(() => subject.complete());
8989

90-
return subject;
90+
return Observable.from(subject);
9191
}
9292

9393
private async renderVariant(operation: RenderVariantOperation<V>): Promise<Snapshot<V>> {

source/application/compiler/webpack/compiler.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import webpack = require('webpack');
22

3+
import chalk = require('chalk');
4+
35
import {sep} from 'path';
46

57
import {createProgram} from 'typescript';
@@ -19,7 +21,16 @@ export class WebpackCompiler implements ApplicationCompiler {
1921
constructor(private project: Project, private loader: ConfigurationLoader) {}
2022

2123
createPlatform(providers: Array<Provider>) {
22-
return createJitPlatform(providers) as ServerPlatform;
24+
try {
25+
return createJitPlatform(providers) as ServerPlatform;
26+
}
27+
catch (exception) {
28+
console.error(chalk.red(`Platform creation failed: this happens when you try to use ${chalk.green('@ngtools/webpack')} during an ng-render build`));
29+
console.error(`Please verify that you are using a regular TypeScript loader, eg ${chalk.green("['ts-loader', 'angular2-template-loader', 'angular-router-loader']")}`);
30+
console.error('This may not be related to your issue, but this a typical cause of this particular exception.');
31+
32+
throw new CompilerException('Failed to create platform instance', exception);
33+
}
2334
}
2435

2536
compile(): Promise<ModuleLoader> {

source/platform/http/pending-requests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ export class PendingRequests {
1515
}
1616

1717
requestsPending(): Observable<number> {
18-
return this.subject;
18+
return Observable.from(this.subject);
1919
}
2020
}

source/platform/platform.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
CompilerOptions,
55
Injectable,
66
Injector,
7+
Inject,
78
NgModuleFactory,
89
NgModuleRef,
910
NgZone,
@@ -24,7 +25,7 @@ export class ServerPlatform implements PlatformRef {
2425

2526
private destroyers = new Array<() => void>();
2627

27-
constructor(public injector: Injector) {}
28+
constructor(@Inject(Injector) public injector: Injector) {}
2829

2930
compileModule<M>(moduleType: Type<M>, compilerOptions: CompilerOptions | Array<CompilerOptions> = []): Promise<NgModuleFactory<M>> {
3031
const compiler = this.getCompiler(compilerOptions);
@@ -100,8 +101,3 @@ export class ServerPlatform implements PlatformRef {
100101
destroyers.forEach(handler => handler());
101102
}
102103
}
103-
104-
Object.assign(ServerPlatform, {
105-
decorators: [{type: Injectable}],
106-
ctorParameters: () => [{type: Injector}]
107-
});

0 commit comments

Comments
 (0)