Integrating angular2 Universal with angular CLI project
-
OS - Windows 8
-
Versions - angular-cli: 1.0.0-beta.5 node: 4.3.1 os: win32 x64
-
Yes, the app was created using CLI
-
Steps - A. Created the app using following command -
ng new testAppB. Installed angular2-universal dependencies as mentioned in -
Angular 2 Universal quickstartC. Deployed client using command -
ng server(server started on port 4200) Started express server through -node server.js(server started on port 3000)D. Accessed the client and got following message in browser - test-app works! But when accessing
http://localhost:3000it gives below error message in console -
EXCEPTION: Error: Protocol "d:" not supported. Expected "http:".
STACKTRACE:
Error: Protocol "d:" not supported. Expected "http:".
at new ClientRequest (_http_client.js:52:11)
at Object.exports.request (http.js:31:10)
at Object.exports.get (http.js:35:21)
at D:\Development\Angular2\angular-cli\cli-angular\testApp\node_modules\angular2-universal\dist\node\platform\node_xhr_impl.js:53:22
at ZoneDelegate.invoke (D:\Development\Angular2\angular-cli\cli-angular\testApp\node_modules\zone.js\dist\zone-node.js:281:29)
at Object.NgZoneImpl.inner.inner.fork.onInvoke (D:\Development\Angular2\angular-cli\cli-angular\testApp\node_modules\@angular\core\src\zone\ng_zone_impl.js:45:41)
at ZoneDelegate.invoke (D:\Development\Angular2\angular-cli\cli-angular\testApp\node_modules\zone.js\dist\zone-node.js:280:35)
at Zone.run (D:\Development\Angular2\angular-cli\cli-angular\testApp\node_modules\zone.js\dist\zone-node.js:174:44)
at NgZoneImpl.runInner (D:\Development\Angular2\angular-cli\cli-angular\testApp\node_modules\@angular\core\src\zone\ng_zone_impl.js:76:71)
at NgZone.run (D:\Development\Angular2\angular-cli\cli-angular\testApp\node_modules\@angular\core\src\zone\ng_zone.js:223:66)
D:\Development\Angular2\angular-cli\cli-angular\testApp\node_modules\@angular\core\src\application_ref.js:302
throw e;
^
Kindly suggest if i had missed any step.
Any help will be appeciated.
You wouldn't need to start the Client separately, if you're using Universal it'll be serving everything through the server only. You want to access port 3000 then. Express is serving the index (w/ the universal app). Give that a shot and let me know
Hi @MarkPieszak, thanks for reverting.
I started the application on port 3000 only as suggested and then accessed the URL, but getting the same error again. I am attaching the screenshot for reference.
Try upgrading Node to 6+ or something, this might be some Express issue. It thinks you're trying to do d://something instead of http:// etc. I think because of your hard-drive directory, bizarre.
You have:
provide(ORIGIN_URL, {useValue: 'http://localhost:3000'}), // <-- localhost3000 in there?
Thanks for the inputs @MarkPieszak, I will try it after upgrading Node to latest version.
Yes, i am having this line in my server.ts file -
provide(ORIGIN_URL, {useValue: 'http://localhost:3000'}),
The Express version that i am referring to is - "express": "^4.13.4"
@MarkPieszak, i had updated the node version to 6.2.1, however i am still getting the same error :(
Version update
Error message-
Please suggest if i am doing something wrong here.
Yeah, the same error happening when you generate app via angular-cli and add server code from https://universal.angular.io/quickstart/
Hi @neilhem, any luck?
no luck, on gitter chat of angular-universal I have written about error, so they told me that they will update code example as soon as possible
@gdi2290 Not sure if this one was on your radar, can't tell if it's CLI or Universal itself
I followed the example as well, but i have totally different errors coming from the server.ts file:
D:/Workspace/bitbucket/stock-front/tmp/broccoli_type_script_compiler-input_base_path-aCaBCBu3.tmp/0/src/server.ts (1, 23): Cannot find module 'path'. D:/Workspace/bitbucket/stock-front/tmp/broccoli_type_script_compiler-input_base_path-aCaBCBu3.tmp/0/src/server.ts (2, 26): Cannot find module 'express'. D:/Workspace/bitbucket/stock-front/tmp/broccoli_type_script_compiler-input_base_path-aCaBCBu3.tmp/0/src/server.ts (3, 29): Cannot find module 'body-parser'. D:/Workspace/bitbucket/stock-front/tmp/broccoli_type_script_compiler-input_base_path-aCaBCBu3.tmp/0/src/server.ts (23, 37): Cannot find name '__dirname'. D:/Workspace/bitbucket/stock-front/tmp/broccoli_type_script_compiler-input_base_path-aCaBCBu3.tmp/0/src/server.ts (29, 18): Cannot find name '__dirname'.
Did you guys had similar problems?
BR
Nevermind, got the same error as well.
EXCEPTION: Error: Protocol "d:" not supported. Expected "http:"
Yeah, the problem was that the typings command failed so I had to add the ambientDependencies manually.
But I still get your error.
BR
On 11 June 2016 at 20:45, Vinod Bhargava [email protected] wrote:
@vaskgjuri https://github.com/vaskgjuri for fixing these errors -
- install the typings as mentioned in angular2-universal IO https://universal.angular.io/quickstart/
- add the reference to the typings in the server.ts file
Above errors should be gone.
Please try these steps and update.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/1050#issuecomment-225383345, or mute the thread https://github.com/notifications/unsubscribe/AGGmXFsw2_ntdRcs3ZLuYDA0uI-Siexpks5qKwJQgaJpZM4Ixuiz .
Med vänlig hälsning | Met vriendelijke groet | Топли поздрави | Kind Regards
Vasko Gjurovski
Tel +38976361002
Bagdatska 15/7 | 1000 Skopje | Macedonia
www.polarcape.com
Polar Cape is representing Sweden in the European Business Awards
Please watch our video and vote http://www.businessawardseurope.com/ for us if you think we should become National Public Champions
http://www.businessawardseurope.com/ http://www.greatplacetowork.se/baesta-arbetsplatser
Polar Cape is one of the best places to work 2015
I did a little more research and I tried to follow this example:
http://mean.expert/2016/06/04/angular-2-loopback-universal/
However, at the end I got the same error message:
Error: Protocol "d:" not supported. Expected "http:"
This is making me think that this might be a problem with a newer version of one of the dependencies, but I just cannot pinpoint which one. Main suspects preboot and angular2-universal.
Still looking...
BR
I'll take a deeper look tomorrow and see if I have any luck integrating the CLI with it. Have you tried the Universal Starter? Also, Universal only works with router-deprecated at this moment, maybe it has something to do with that.
I did try the Universal starter and it was working fine, but as the CLI is the recommended way of "managing" your app, it was only logical that we use the CLI with Universal. And, no, I did not know that Universal works with router-deprecated at the moment, which would be a huge drawback, as now it is 2 versions behind (with the announcement of the 3.0 Router).
And, thanks for the help... :)
BR
On 11 June 2016 at 23:55, Mark Pieszak [email protected] wrote:
I'll take a deeper look tomorrow and see if I have any luck integrating the CLI with it. Have you tried the Universal Starter? Also, Universal only works with router-deprecated at this moment, maybe it has something to do with that.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/1050#issuecomment-225396651, or mute the thread https://github.com/notifications/unsubscribe/AGGmXLxwV9new6GzBlbhU9_37Ui9QQCjks5qKy7jgaJpZM4Ixuiz .
Med vänlig hälsning | Met vriendelijke groet | Топли поздрави | Kind Regards
Vasko Gjurovski
Tel +38976361002
Bagdatska 15/7 | 1000 Skopje | Macedonia
www.polarcape.com
Polar Cape is representing Sweden in the European Business Awards
Please watch our video and vote http://www.businessawardseurope.com/ for us if you think we should become National Public Champions
http://www.businessawardseurope.com/ http://www.greatplacetowork.se/baesta-arbetsplatser
Polar Cape is one of the best places to work 2015
FYI, I did try a stripped version of my app with the router-deprecated and it still gives the same error:
EXCEPTION: Error: Protocol "d:" not supported. Expected "http:"
So I do not think it is the router that makes the problem.
BR
On 12 June 2016 at 03:18, Vasko Gjurovski [email protected] wrote:
I did try the Universal starter and it was working fine, but as the CLI is the recommended way of "managing" your app, it was only logical that we use the CLI with Universal. And, no, I did not know that Universal works with router-deprecated at the moment, which would be a huge drawback, as now it is 2 versions behind (with the announcement of the 3.0 Router).
And, thanks for the help... :)
BR
On 11 June 2016 at 23:55, Mark Pieszak [email protected] wrote:
I'll take a deeper look tomorrow and see if I have any luck integrating the CLI with it. Have you tried the Universal Starter? Also, Universal only works with router-deprecated at this moment, maybe it has something to do with that.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/1050#issuecomment-225396651, or mute the thread https://github.com/notifications/unsubscribe/AGGmXLxwV9new6GzBlbhU9_37Ui9QQCjks5qKy7jgaJpZM4Ixuiz .
Med vänlig hälsning | Met vriendelijke groet | Топли поздрави | Kind Regards
Vasko Gjurovski
Tel +38976361002
Bagdatska 15/7 | 1000 Skopje | Macedonia
www.polarcape.comPolar Cape is representing Sweden in the European Business Awards
Please watch our video and vote http://www.businessawardseurope.com/ for us if you think we should become National Public Champions
http://www.businessawardseurope.com/ http://www.greatplacetowork.se/baesta-arbetsplatser
Polar Cape is one of the best places to work 2015
Med vänlig hälsning | Met vriendelijke groet | Топли поздрави | Kind Regards
Vasko Gjurovski
Tel +38976361002
Bagdatska 15/7 | 1000 Skopje | Macedonia
www.polarcape.com
Polar Cape is representing Sweden in the European Business Awards
Please watch our video and vote http://www.businessawardseurope.com/ for us if you think we should become National Public Champions
http://www.businessawardseurope.com/ http://www.greatplacetowork.se/baesta-arbetsplatser
Polar Cape is one of the best places to work 2015
Ok I'll take a look, yeah we haven't upgraded it yet mainly because of the ever changing router states, of course for the newest one we will update it as quickly as we can!
shouldn't angular CLI support universal from ground up?
e.g. ng generate universal node/asp.net
Unfortunately I don't think it could from the way it is now, because asp.net for example has an extremely different setup than a typical ng2 project.
It would have to be an add-on to the CLI if they had it, since it would be very different itself.
Steve Sanderson made a nice yeoman generator for asp.net core and angular2 (it's using Universal as well) if you want to take a look at it. http://blog.stevensanderson.com/2016/05/02/angular2-react-knockout-apps-on-aspnet-core/
thanks for the link. Is it possible/usable to combine this with angular CLI?