Angular-cli: Angular univeral - problem with server.ts

Created on 14 Dec 2017  路  15Comments  路  Source: angular/angular-cli

Versions

Angular CLI: 1.6.1
Node: 6.9.5
OS: win32 x64
Angular: 5.1.1
... animations, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic
... platform-server, router

@angular/cli: 1.6.1
@angular/language-service: 4.3.6
@angular-devkit/build-optimizer: 0.0.36
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.42
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.1
@schematics/angular: 0.1.11
@schematics/schematics: 0.0.11
typescript: 2.6.2
webpack: 3.10.0

I have tried to get angular unversal to work, but im getting this error
ERROR in ./server.ts
Module not found: Error: Can't resolve './dist/server/main.bundle' in '
@ ./server.ts 16:9-45

I have followed the guid here : https://angular.io/guide/universal#app-server-module

Any ides on what can be the problem?

bufix

All 15 comments

@heavyflames Does this works ok on 1.6.0?

@Tallyb Hi, do you mean Angular CLI 1.6?

@heavyflames yes - Angular cli 1.6.0. We also encountered issues with 1.6.1

@Tallyb sadly it did not work with cli 1.6.0 either, same error :/

I got the server to start now, but when i hit the site in the browser i get another error

TypeError: Cannot read property 'create' of undefined

And its pointing to server.js at this function.

Specific row :
var /* @type {?} */ moduleRef = /* @type {?} */ (moduleFactory.create(ngZoneInjector));

function (moduleFactory, options) {
var _this = this;
// Note: We need to create the NgZone _before_ we instantiate the module,
// as instantiating the module creates some providers eagerly.
// So we create a mini parent injector that just contains the new NgZone and
// pass that as parent to the NgModuleFactory.
var /* @type {?} */ ngZoneOption = options ? options.ngZone : undefined;
var /
* @type {?} / ngZone = getNgZone(ngZoneOption);
// Attention: Don't use ApplicationRef.run here,
// as we want to be sure that all possible constructor calls are inside ngZone.run!
return ngZone.run(function () {
var /
* @type {?} / ngZoneInjector = Injector.create([{ provide: NgZone, useValue: ngZone }], _this.injector);
var /
* @type {?} / moduleRef = /* @type {?} / (moduleFactory.create(ngZoneInjector));
var /
* @type {?} / exceptionHandler = moduleRef.injector.get(ErrorHandler, null);
if (!exceptionHandler) {
throw new Error('No ErrorHandler. Is platform module (BrowserModule) included?');
}
moduleRef.onDestroy(function () { return remove(_this._modules, moduleRef); }); /
* @type {?} /
((ngZone)).runOutsideAngular(function () { return ((ngZone)).onError.subscribe({ next: function (error) { exceptionHandler.handleError(error); } }); });
return _callAndReportToErrorHandler(exceptionHandler, /
* @type {?} / ((ngZone)), function () {
var /
* @type {?} */ initStatus = moduleRef.injector.get(ApplicationInitStatus);
initStatus.runInitializers();
return initStatus.donePromise.then(function () {
_this._moduleDoBootstrap(moduleRef);
return moduleRef;
});
});
});
};

This is during run time right? Can you include a repo or directory structure? It's possible that you're pointing to the wrong path.

Is that the relative path to your main.bundle from your compiled server.ts?

Can we have any solution for that, I am also facing the same problem.

I am also facing the same prob. pls anyone help me

You need to change 'outDir' in .angular-cli:

"apps": [
    {
      "outDir": "dist/browser" // <-- update this for browser app
    },
    {
      "outDir": "dist/server" // <-- update this for server app
     }
]

Also look here https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/universal-rendering.md

@Yura13 I did that already, but still getting the same error

probably because my dist/server folder has main.[hashcode].js instead of main.bundle.js

@mohammedzamakhan
ng build --prod --output-hashing=false for the Universal app

@mohammedzamakhan Try to compare your server.ts with the example from https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/universal-rendering.md#step-4-setting-up-an-express-server-to-run-our-universal-bundles

I'm sorry, but we can't reproduce the problem following the instructions you provided.
Remember that we have a large number of issues to resolve, and have only a limited amount of time to reproduce your issue.
Short, explicit instructions make it much more likely we'll be able to reproduce the problem so we can fix it.

If the problem persists, please open a new issue following our submission guidelines.

A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brtnshrdr picture brtnshrdr  路  3Comments

rajjejosefsson picture rajjejosefsson  路  3Comments

IngvarKofoed picture IngvarKofoed  路  3Comments

hartjo picture hartjo  路  3Comments

purushottamjha picture purushottamjha  路  3Comments