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

@devCrossNet I see. Thanks for clarifying.

Looks like PR https://github.com/angular/angular-cli/pull/5194 is where we are at. Seems like that one is necessary to get the rest of it working. Appears to have been some commit activity five days ago. Of course @FrozenPandaz is the best person to comment on all those though.

somombo avatar May 09 '17 10:05 somombo

Looks like #5194 has been merged into master a few hours ago. Where does this leave us?

markwhitfeld avatar May 23 '17 06:05 markwhitfeld

Leaves us waiting for a release now :)

hheexx avatar May 23 '17 12:05 hheexx

I think we need https://github.com/angular/angular-cli/pull/5547 too. Somebody should rebase to fix the conflict and write unit test to approve it.

kondi avatar May 23 '17 12:05 kondi

According to @FrozenPandaz it does not depend on #5547. Where do we go from here?

fareesh avatar May 24 '17 12:05 fareesh

Yes, the other PR (#5194) does not depend on #5547. So now the server bootstrap code is replaced as well.

But the feature what we want to have (interating universal into angular cli) needs #5547 to build the correct bundle for NodeJS.

kondi avatar May 24 '17 12:05 kondi

@kondi Gotcha, thanks!

fareesh avatar May 24 '17 13:05 fareesh

is this coming soon?

mohamed-rekiba avatar May 27 '17 11:05 mohamed-rekiba

Who owns this? Any update?

kylestephens avatar Jun 02 '17 02:06 kylestephens

UP! It would be really nice to be able to make pre-rendered apps without giving up on the CLI. The CLI is very useful for development.

glemiere avatar Jun 11 '17 01:06 glemiere

To wait you can style clone this project : https://github.com/designcourse/angular-seo. Hope I'm saving some lives lol

glemiere avatar Jun 12 '17 22:06 glemiere

@glemiere unfortunately, if I add a lazy module into that, it doesn't get rendered server side.

ERROR { Error: Uncaught (in promise): ReferenceError: System is not defined
ReferenceError: System is not defined

Also, I can't figure out how to access cookies server side. Went back and forth between different examples found across GitHub, but they're very different from the example in your link, I can't make anything out of them (plus, most are using a unversal-starter).

Have you managed to make it work with lazy modules or read cookies server side?

NgxDev avatar Jun 18 '17 13:06 NgxDev

angular2-cookie has a working implementation for server side. It involves having a separate provider for node and using Zone.current

On Sun 18 Jun, 2017, 6:44 PM Marian Stoica, [email protected] wrote:

@glemiere https://github.com/glemiere unfortunately, if I add a lazy module into that https://github.com/designcourse/angular-seo, it doesn't get rendered server side.

ERROR { Error: Uncaught (in promise): ReferenceError: System is not defined ReferenceError: System is not defined

Also, I can't figure out how to access cookies server side. Went back and forth between different examples found across GitHub, but they're very different from the example in your link, I can't make anything out of them.

Have you managed to make it work with lazy modules or read cookies server side?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/1050#issuecomment-309277059, or mute the thread https://github.com/notifications/unsubscribe-auth/AAeZ8SGRnnTAQu7Q05WLCVIsW-I5enBDks5sFSLNgaJpZM4Ixuiz .

fareesh avatar Jun 18 '17 13:06 fareesh

@glemiere I have the same issue as @MrCroft. Is there any solution for lazy loaded modules rendering?

When this feature will be supported?

alkuzman avatar Jun 19 '17 18:06 alkuzman

@Brocco At large scale angular site is taking 30 seconds for first meaningful paint on slower network. Could you please give us a time line for SSR. I don't want to switch from CLI.

raghav-reglobe avatar Jun 23 '17 10:06 raghav-reglobe

Guys, any news? This feature is really important @MarkPieszak

glebmachine avatar Jun 27 '17 10:06 glebmachine

@glebmachine as far as I know, there's 1x PR left and it has a very small change before it can be merged: https://github.com/angular/angular-cli/pull/5547

intellix avatar Jun 27 '17 10:06 intellix

Dear god, i hope it will be done soon!)

glebmachine avatar Jun 27 '17 10:06 glebmachine

any good example right now, how to integrate server side rendering with angular cli?

P.S. I am quite disappointed in support of angular-cli team, it looks like noone cares about this issue

dimitriy-k avatar Jul 06 '17 06:07 dimitriy-k

@dimitriy-k and anyone else looking, then the best example I have found for at server side rendered solution with angular cli is this article: https://coursetro.com/posts/code/68/Make-your-Angular-App-SEO-Friendly-(Angular-4-+-Universal)

The biggest issue though, is that the server code is only running through ngc and not webpack. Therefor all loaders (sass etc.) and environment variables are not passed to the server side code and will not work.

mikkeldamm avatar Jul 06 '17 08:07 mikkeldamm