angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Integrating angular2 Universal with angular CLI project

Open vinodbhargava opened this issue 10 years ago • 214 comments

  1. OS - Windows 8

  2. Versions - angular-cli: 1.0.0-beta.5 node: 4.3.1 os: win32 x64

  3. Yes, the app was created using CLI

  4. Steps - A. Created the app using following command - ng new testApp

    B. Installed angular2-universal dependencies as mentioned in -
    Angular 2 Universal quickstart

    C. 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:3000 it 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.

vinodbhargava avatar Jun 09 '16 08:06 vinodbhargava

Thanks @MarkPieszak . that really helps :)

ritz078 avatar Sep 02 '16 13:09 ritz078

will there be asp.net support on server side?

doczoidberg avatar Sep 03 '16 00:09 doczoidberg

Any updates of this? Is angular universal usable with the CLI?

theunreal avatar Sep 27 '16 18:09 theunreal

@theunreal @ritz078 @goelinsights @dottodot @vinodbhargava @neilhem @vaskgjuri

There is an open PR for the CLI here: https://github.com/angular/angular-cli/pull/2318 I'm not sure exactly when it will be merged, but soon there will be --universal support :+1:

You can thank @DevCrossNet :sparkles:

MarkPieszak avatar Sep 27 '16 18:09 MarkPieszak

any news on this? seems like there's 10 different threads around this, all forwarded on to the next

gruckus-gruckus avatar Oct 24 '16 03:10 gruckus-gruckus

Still no updates on this? Adding the --universal flag to the CLI?

daygon2007 avatar Nov 07 '16 19:11 daygon2007

We have some trouble to publish it. You can already use it. Check out the universal-webpack branch in my fork. It will be published soon. Sorry that it takes so long.

devCrossNet avatar Nov 07 '16 20:11 devCrossNet

@devCrossNet will someone comment here when it is published? I'm sure that many (including myself) are waiting on this delicious addition to the cli.

after-ephemera avatar Nov 07 '16 22:11 after-ephemera

@azjkjensen yes, I will comment here and tell you how to install it. I have to change a lot since it will not be integrated in the angular-cli project. Therefore we have a lot to test in the first release.

devCrossNet avatar Nov 08 '16 08:11 devCrossNet

@devCrossNet Is it going to be a separate project which will generate angular universal ? And another question. How do i make prodaction folder with server file in to dist folder. Because now if i clone your repo universal-webpack and after run ng build --prod i do not get server file in dist folder there fore i cen not configure package json to run server from the dist.

goriunov avatar Nov 08 '16 09:11 goriunov

@goriunov it will be a separate npm package. But it will be always up to date with the angular-cli project. So you have everything from both worlds. It'll work like the angular-cli but with an additional flag --universal. You should already have a production bundle for the server in ./dist/server.bundle.js, if not you've found a bug.

devCrossNet avatar Nov 08 '16 10:11 devCrossNet

@devCrossNet I suppose this is temporary. And ultimately, we will only have one angular-cli package. I don't know what could have changed so drastically that would also affect the "regular" usage (without the --universal flag) and needing to be a whole separate package... only difference should be whether or not I want to use the --universal flag, no?... Or is this "split" because (for a while at least) there will probably be more releases for the universal version (bug fixing/features etc.)...

NgxDev avatar Nov 08 '16 10:11 NgxDev

@MrCroft I planned to have it as a separate channel on angular-cli, like angular-cli@universal. But the core team has not enough time to review changes that are not part of the core angular-cli project. And they also have not enough time to publish every time I want to publish something new. So they came up with this solution. But with the nextGen of angular-cli it will be much easier to implement things like universal support. So we have to wait for the nextGen to get a better solution. An alternative would be to not publish it and just leave it as a fork and everyone that wants to use it, uses git clone and install it locally.

devCrossNet avatar Nov 08 '16 10:11 devCrossNet

I published the first version of universal-cli, you can install it with npm install -g universal-cli and if you want to create a universal project type ng new <appname> --universal. Feel free to contribute, file issues, etc.

devCrossNet avatar Nov 08 '16 12:11 devCrossNet

@devCrossNet Is there a repo for this or is this just the branch you mentioned? Just wondering for bug reporting if I happen to find any.

BTW, Thank you so much, the only thing keeping me from going strictly to angular 2 was the SPA SEO issues and universal solves that as well as the ease of the CLI.

daygon2007 avatar Nov 08 '16 16:11 daygon2007

@daygon2007 this is the project page: https://github.com/devCrossNet/angular-cli. have fun! :-)

devCrossNet avatar Nov 08 '16 16:11 devCrossNet

Hello @devCrossNet, I just checked your universal-cli >) Thank you for work). In generated project we have file polyfills.ts however i have not found any places where we use this file. Should we import it in the client.ts?

And i have not found any way to create issue in https://github.com/devCrossNet/angular-cli.

goriunov avatar Nov 08 '16 19:11 goriunov

@goriunov sorry, I did not have enabled the issues. It is now enabled.

devCrossNet avatar Nov 08 '16 21:11 devCrossNet

@devCrossNet could you clarify what you mean by cli "nextGen"? Since the flow of information is .. less than ideal. Is there some kind of breaking changes coming down the road?

Renader avatar Nov 10 '16 12:11 Renader

@Renader as the repo of angular-cli says "Prototype of a CLI for Angular 2 applications based on the ember-cli project.". There are discussions about, how can the CLI be more extensible (e.g. universal, mobile). Best would be some kind of plugin system, that you can create a universal plugin and the plugin author has to his job on quality and stuff and not the core team. It should not change the result of the CLI (structure, commands, etc.). It is more a change for developers. But I don't know the big picture. I think it is a difficult topic and they have to do a lot of thinking to create a proper plugin system.

devCrossNet avatar Nov 10 '16 14:11 devCrossNet