Server side error. Promise uncaught?
See original GitHub issueBug Report
What is the expected behavior?
server side to execute http requests and render lazy loaded modules as expected… i’ve gone through all my http promises and caught them but the line number references seem very early on in server.js which is angular code? anyone know whats going on?
server side throws error shown bellow then the client is sent and rendered normally on the client with no errors.
ERROR { Error: Uncaught (in promise): Error
at resolvePromise (root\to\workspace\dist\server.js:1040:31)
at resolvePromise (root\to\workspace\dist\dist\server.js:997:17)
at root\to\workspace\dist\dist\server.js:1099:17
at ZoneDelegate.invokeTask (root\to\workspace\dist\dist\server.js:647:31)
at Object.onInvokeTask (root\to\workspace\dist\dist\server.js:7804:33)
at ZoneDelegate.invokeTask (root\to\workspace\dist\dist\server.js:646:36)
at Zone.runTask root\to\workspace\dist\dist\server.js:414:47)
at drainMicroTaskQueue root\to\workspace\dist\dist\server.js:821:35)
at ZoneTask.invokeTask (root\to\workspace\dist\dist\server.js:726:21)
at Server.ZoneTask.invoke (root\to\workspace\dist\dist\server.js:711:48)
rejection: [Error],
promise: ZoneAwarePromise { __zone_symbol__state: 0, __zone_symbol__value: [Error] },
zone:
Zone {
_properties: { isAngularZone: true },
_parent:
Zone {
_properties: {},
_parent: null,
_name: '<root>',
_zoneDelegate: [Object] },
_name: 'angular',
_zoneDelegate:
ZoneDelegate {
_taskCounts: [Object],
zone: [Circular],
_parentDelegate: [Object],
_forkZS: null,
_forkDlgt: null,
_forkCurrZone: [Object],
_interceptZS: null,
_interceptDlgt: null,
_interceptCurrZone: [Object],
_invokeZS: [Object],
_invokeDlgt: [Object],
_invokeCurrZone: [Circular],
_handleErrorZS: [Object],
_handleErrorDlgt: [Object],
_handleErrorCurrZone: [Circular],
_scheduleTaskZS: [Object],
_scheduleTaskDlgt: [Object],
_scheduleTaskCurrZone: [Circular],
_invokeTaskZS: [Object],
_invokeTaskDlgt: [Object],
_invokeTaskCurrZone: [Circular],
_cancelTaskZS: [Object],
_cancelTaskDlgt: [Object],
_cancelTaskCurrZone: [Circular],
_hasTaskZS: [Object],
_hasTaskDlgt: [Object],
_hasTaskDlgtOwner: [Circular],
_hasTaskCurrZone: [Circular] } },
task:
ZoneTask {
_zone:
Zone {
_properties: [Object],
_parent: [Object],
_name: 'angular',
_zoneDelegate: [Object] },
runCount: 0,
_zoneDelegates: null,
_state: 'notScheduled',
type: 'microTask',
source: 'Promise.then',
data: ZoneAwarePromise { __zone_symbol__state: 0, __zone_symbol__value: [Error] },
scheduleFn: undefined,
cancelFn: null,
callback: [Function],
invoke: [Function] } }
main.ts
import {enableProdMode} from '@angular/core';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {AppModule} from './app/app.module';
import {environment} from './environments/environment';
if (environment.production) {
enableProdMode();
}
document.addEventListener('DOMContentLoaded', () => {
platformBrowserDynamic()
.bootstrapModule(AppModule)
.catch(err => console.log(err));
});
server.ts
import 'zone.js/dist/zone-node';
import 'reflect-metadata';
import {enableProdMode} from '@angular/core';
import * as express from 'express';
import * as csp from 'helmet-csp';
import * as helmet from 'helmet';
import {join} from 'path';
// Express Engine
// Import module map for lazy loading
import {provideModuleMap} from '@nguniversal/module-map-ngfactory-loader';
import {ngExpressEngine} from '@nguniversal/express-engine';
import {REQUEST, RESPONSE} from '@nguniversal/express-engine/tokens';
// Faster server renders w/ Prod mode (dev mode never needed)
enableProdMode();
// Express server
const app = express();
const proxy = require('http-proxy-middleware');
// CHANGE FOR DEV (npm run server)
const apiLB = process.env.API_URI || 'http://localhost:4002';
const PORT = process.env.PORT || 4000;
const DIST_FOLDER = join(process.cwd(), 'dist');
// * NOTE :: leave this as require() since this files is built Dynamically from webpack
const {AppServerModuleNgFactory, LAZY_MODULE_MAP} = require('./dist/server/main');
app.engine('html', (_, options, callback) =>
ngExpressEngine({
bootstrap: AppServerModuleNgFactory,
providers: [
provideModuleMap(LAZY_MODULE_MAP),
{
provide: REQUEST,
useValue: options.req,
},
{
provide: RESPONSE,
useValue: options.req.res,
},
],
})(_, options, callback)
);
// proxy requests to the api lb for api requests
app.use('/api', proxy({
target: apiLB,
}));
app.set('view engine', 'html');
app.set('views', join(DIST_FOLDER, 'browser'));
app.use(helmet());
app.use(helmet.referrerPolicy({
policy: 'same-origin'
}));
app.disable('x-powered-by');
// Server static files from /browser
app.get('*.*', express.static(join(DIST_FOLDER, 'browser'), {
maxAge: '1y'
}));
// ALl regular routes use the Universal engine
app.get('*', (req, res) => {
res.render('index', {req});
});
// Start up the Node server
app.listen(PORT, () => {
console.log(`Node Express server listening on http://localhost:${PORT}`);
});
it may have something to do with lazy loading?
What modules are related to this issue?
- [ ] aspnetcore-engine
- [ ] common
- [ *] express-engine
- [ ] hapi-engine
- [ *] module-map-ngfactory-loader
Environment:
@nguniversal versions
- express-engine:
- module-map-ngfactory-loader:
Angular CLI: 6.1.5
Node: 8.11.4
OS: win32 x64
Angular: 6.1.6
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.7.5
@angular-devkit/build-angular 0.7.5
@angular-devkit/build-optimizer 0.7.5
@angular-devkit/build-webpack 0.7.5
@angular-devkit/core 0.7.5
@angular-devkit/schematics 0.7.5
@angular/cli 6.1.5
@ngtools/webpack 6.1.5
@schematics/angular 0.7.5
@schematics/update 0.7.5
rxjs 6.3.2
typescript 2.9.2
webpack 4.9.2
Windows (10)
Issue Analytics
- State:
- Created 5 years ago
- Comments:12
Top Results From Across the Web
Uncaught (in promise): ReferenceError: document is not ...
While trying to use ssr, you don't have access to any DOM on the server side, hence you are getting such errors. If...
Read more >Error handling with promises
The promise returned by fetch rejects when it's impossible to make a request. For instance, a remote server is not available, or the...
Read more >Promises - Error Handling - Beginner JavaScript - Wes Bos
What does that log "Uncaught (in promise)" mean? It means that there was an error in one of our promises, but we did...
Read more >Using Express.js Routes for Promise-based Error Handling
Maintainable Express.js code after scaling means making common code more feature-rich while reducing boilerplate. Find out how to enable promise-based route ...
Read more >Promise() constructor - JavaScript - MDN Web Docs
The rejectFunc has semantics close to the throw statement, so reason is typically an Error instance. If either value or reason is omitted,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi … new update … now it works perfect … the prob (i think) was related to the Lazy loaded Routes … there were NO ‘normal’ route (ALL routes were lazy loaded) … now we have one deafult eager route/component …and it looks ok … THNX for you support!!!
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.