question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Angular6 universal giving continues Error on node console

See original GitHub issue

Bug Report

I have followed the same steps as explained in the documentation in https://angular.io/guide/universal

Everything works fine but don’t know why I am getting below error on server continuously.

Running on the server with appId=***** ERROR [Error] ERROR [Error] Running on the server with appId=***** ERROR [Error] ERROR [Error] Running on the server with appId=***** ERROR [Error] ERROR [Error]

my server.ts file

import 'zone.js/dist/zone-node';
import 'reflect-metadata';

import { enableProdMode } from '@angular/core';

import * as express from 'express';
import { join } from 'path';
// Express Engine
import { ngExpressEngine } from '@nguniversal/express-engine';
// Import module map for lazy loading
import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader';

// Faster server renders w/ Prod mode (dev mode never needed)
enableProdMode();

// node run port
const port = 6065;

// Express server
const app = express();

const PORT = port || process.env.PORT;
const DIST_FOLDER = join(process.cwd(), 'dist');

const domino = require('domino');
const fs = require('fs');
const MockBrowser = require('mock-browser').mocks.MockBrowser;
const mock = new MockBrowser();

const template = fs
    .readFileSync(join(DIST_FOLDER, 'browser', 'index.html'))
    .toString();
// Make all Domino types available as types in the global env.
Object.assign(global, domino.impl);
(global as any)['KeyboardEvent'] = domino.impl.Event;
const win = domino.createWindow(template);
win.Object = Object;
win.Math = Math;

global['window'] = win;
global['document'] = win.document;
global['navigator'] = mock.getNavigator();
global['branch'] = null;
global['object'] = win.object;
global['HTMLElement'] = win.HTMLElement;
global['DOMTokenList'] = win.DOMTokenList;
global['Node'] = win.Node;
global['Text'] = win.Text;

// * NOTE :: leave this as require() since this file is built Dynamically from webpack
const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist/server/main');

app.engine('html', ngExpressEngine({
    bootstrap: AppServerModuleNgFactory,
    providers: [
        provideModuleMap(LAZY_MODULE_MAP)
    ]
}));

app.set('view engine', 'html');
app.set('views', join(DIST_FOLDER, 'browser'));

// TODO: implement data requests securely
app.get('/api/*', (req, res) => {
    res.status(404).send('data requests are not supported');
});

// Server static files from /browser
app.get('*.*', express.static(join(DIST_FOLDER, 'browser')));

// All regular routes use the Universal engine
app.get('*', (req, res) => {
    res.render('index', { req });
});

// Start up the Node server
app.listen(PORT, '0.0.0.0', () => {
    console.log(`Node server listening on http://localhost:${PORT}`);
});

What modules are related to this issue?

- [ ] @angular/platform-server
- [ ] @nguniversal/module-map-ngfactory-loader
- [ ] express-engine
- [ ] module-map-ngfactory-loader

Environment:

@nguniversal versions

<!--
Output from: `ng --version`.
Angular CLI: 6.1.3
Node: 8.11.3
OS: darwin x64
Angular: 6.1.10
... animations, common, compiler, core, forms, http
... language-service, platform-browser, platform-browser-dynamic
... platform-server, router, upgrade

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.7.0
@angular-devkit/build-angular     0.7.0
@angular-devkit/build-optimizer   0.7.0
@angular-devkit/build-webpack     0.7.0
@angular-devkit/core              0.7.0
@angular-devkit/schematics        0.7.3
@angular/cdk                      6.4.7
@angular/cli                      6.1.3
@angular/compiler-cli             6.1.0
@angular/material                 6.4.7
@ngtools/webpack                  6.1.0
@schematics/angular               0.7.3
@schematics/update                0.7.3
rxjs                              6.3.3
typescript                        2.7.2
webpack                           4.9.2
-->

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
vikash09commented, Apr 1, 2019

@nimatullah Yes,

import { TranslateService } from '@ngx-translate/core';
import { Injectable, PLATFORM_ID, Inject } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';

The problem was in TranslateService

I solved it by checking the condition

 constructor(@Inject(PLATFORM_ID) private platformId: Object
 public translate: TranslateService   ) {

if (isPlatformBrowser(this.platformId)) {
           this.translate.setDefaultLang('en');
            this.translate.use('en');
        }
}
0reactions
angular-automatic-lock-bot[bot]commented, Sep 4, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Angular6 universal giving continues Error on console
I am using angular 6 and implemented the angular universal for server side page rendering, Everything works fine but I am getting continues...
Read more >
Angular6 universal giving continues Error on console-node.js
js in my Visual Studio Code and what I had found: an error messages was caused by http requests from TranslateHttpLoader (I'm using...
Read more >
Process | Node.js v19.3.0 Documentation
The 'rejectionHandled' event is emitted whenever a Promise has been rejected and an error handler was attached to it (using promise.catch() , for...
Read more >
Angular 6 vs Angular 7 vs Angular 8 vs Angular 9
Service workers come with some bug fixes, including some new functionalities as there was no straight way for deactivating the service worker ...
Read more >
Angular Universal and Server Side Rendering (Step By Step)
As we learned before, angular is also capable of running on node.js servers. Because of that, it is also possible to generate that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found