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.

Impossible to start SSR : A server error occured

See original GitHub issue

🐞 Bug report

What modules are related to this issue?

One of the two following ones, not sure…

  • aspnetcore-engine
  • builders
  • common
  • express-engine
  • hapi-engine

Description

I am trying to move my application to Angular Universal. After running npm install -g @angular/cli and updating a few configs (tsconfig.server.json, angular.json and app.module.ts) to fix first issues, I am seeing an error when running npm run dev:ssr.

🔬 Minimal Reproduction

The few changes I did to fix first issues when trying to start the app were :

  • adding BrowserModule to app.module.ts
  • updating the environments in angular.json so the names match the ones defined in our project
  • adding hammerjs to the types list in tsconfig.server.json

🔥 Exception or Error




***/dist/***/server/main.js:1
var __defProp=Object.defineProperty,__name=(target,value)=>__defProp(target,"name",{value,configurable:!0});(()=>{var __webpack_modules__={42121:(module2,__unused_webpack_exports2,__webpack_require__2)=>{"use strict";var Negotiator=__webpack_require__2(14720),mime=__webpack_require__2(70394);function Accepts(req){if(!(this instanceof Accepts))return new Accepts(req);this.headers=req.headers,this.negotiator=new Negotiator(req)}function extToMime(type){return-1===type.indexOf("/")?mime.lookup(type):type}function validMime(type){return"string"==typeof type}module2.exports=Accepts,__name(Accepts,"Accepts"),Accepts.prototype.type=Accepts.prototype.types=function(types_){var types=types_;if(types&&!Array.isArray(types)){types=new Array(arguments.length);for(var i2=0;i2<types.length;i2++)types[i2]=arguments[i2]}if(!types||0===types.length)return this.negotiator.mediaTypes();if(!this.headers.accept)return types[0];var mimes=types.map(extToMime),accepts=this.negotiator.mediaTypes(mimes.filter(validMime)),first=accepts[0];return!!first&&types[mimes.indexOf(first)]},Accepts.prototype.encoding=Accepts.prototype.encodings=function(encodings_){var encodings=encodings_;if(encodings&&!Array.isArray(encodings)){encodings=new Array(arguments.length);for(var i2=0;i2<encodings.length;i2++)encodings[i2]=arguments[i2]}return encodings&&0!==encodings.length?this.negotiator.encodings(encodings)[0]||!1:this.negotiator.encodings()},Accepts.prototype.charset=Accepts.prototype.charsets=function(charsets_){var charsets=charsets_;if(charsets&&!Array.isArray(charsets)){charsets=new Array(arguments.length);for(var i2=0;i2<charsets.length;i2++)charsets[i2]=arguments[i2]}return charsets&&0!==charsets.length?this.negotiator.charsets(charsets)[0]||!1:this.negotiator.charsets()},Accepts.prototype.lang=Accepts.prototype.langs=Accepts.prototype.language=Accepts.prototype.languages=function(languages_){var languages=languages_;if(languages&&!Array.isArray(languages)){languages=new Array(arguments.length);for(var i2=0;i2<languages.length;i2++)languages[i2]=arguments[i2]}return languages&&0!==languages.length?this.negotiator.languages(languages)[0]||!1:this.negotiator.languages()},__name(extToMime,"extToMime"),__name(validMime,"validMime")},6645:(module2,exports2,__webpack_require__2)=>{"use strict";var deprecate2=__webpack_require__2(73546)("body-parser"),parsers=Object.create(null);function bodyParser(options){var opts={};if(options)for(var prop in options)"type"!==prop&&(opts[prop]=options[prop]);var _urlencoded=exports2.urlencoded(opts),_json=exports2.json(opts);return __name(function(req,res,next){_json(req,res,function(err2){if(err2)return next(err2);_urlencoded(req,res,next)})},"bodyParser")}function createParserGetter(name){return __name(function(){return loadParser(name)},"get")}function loadParser(parserName){var parser=parsers[parserName];if(void 0!==parser)return parser;switch(parserName){case"json":parser=__webpack_require__2(8714);break;case"raw":parser=__webpack_require__2(95108);break;case"text":parser=__webpack_require__2(8824);break;case"urlencoded":parser=__webpack_require__2(90570)}return parsers[parserName]=parser}exports2=module2.exports=deprecate2.function(bodyParser,"bodyParser: use individual json/urlencoded middlewares"),Object.defineProperty(exports2,"json",{configurable:!0,enumerable:!0,get:createParserGetter("json")}),Object.defineProperty(exports2,"raw",{configurable:!0,enumerable:!0,get:createParserGetter("raw")}),Object.defineProperty(exports2,"text",{configurable:!0,enumerable:!0,get:createParserGetter("text")}),Object.defineProperty(exports2,"urlencoded",{configurable:!0,enumerable:!0,get:createParserGetter("urlencoded")}),__name(bodyParser,"bodyParser"),__name(createParserGetter,"createParserGetter"),__name(loadParser,"loadParser")},76421:(module2,__unused_webpack_exports2,__webpack_require__2)=>{"use strict";var createError=__webpack_require__2(41347),getBody=__webpack_require__2(67386),iconv=__webpack_require__2(41614),onFinished=__webpack_require__2(99669),zlib=__webpack_require__2(59796);function read(req,res,next,parse,debug,options){var length,stream,opts=options;req._body=!0;var encoding=null!==opts.encoding?opts.encoding:null,verify=opts.verify;try{length=(stream=contentstream(req,debug,opts.inflate)).length,stream.length=void 0}catch(err2){return next(err2)}if(opts.length=length,opts.encoding=verify?null:encoding,null===opts.encoding&&null!==encoding&&!iconv.encodingExists(encoding))return next(createError(415,'unsupported charset "'+encoding.toUpperCase()+'"',{charset:encoding.toLowerCase(),type:"charset.unsupported"}));debug("read body"),getBody(stream,opts,function(error,body){var _error;if(error)return _error="encoding.unsupported"===error.type?createError(415,'unsupported charset "'+encoding.toUpperCase()+'"',{charset:encoding.toLowerCase(),type:"charset.unsupported"}):createError(400,error),stream.resume(),void onFinished(req,__name(function(){next(createError(400,_error))},"onfinished"));if(verify)try{debug("verify body"),verify(req,res,body,encoding)}catch(err2){return void next(createError(403,err2,{body,type:err2.type||"entity.verify.failed"}))}var str=body;try{debug("parse body"),str="string"!=typeof body&&null!==encoding?iconv.decode(body,encoding):body,req.body=parse(str)}catch(err2){return void next(createError(400,err2,{body:str,type:err2.type||"entity.parse.failed"}))}next()})}function contentstream(req,debug,inflate){var stream,encoding=(req.headers["content-encoding"]||"identity").toLowerCase(),length=req.headers["content-length"];if(debug('content-encoding "%s"',encoding),!1===inflate&&"identity"!==encoding)throw createError(415,"content encoding unsupported",{encoding,type:"encoding.unsupported"});switch(encoding){case"deflate":stream=zlib.createInflate(),debug("inflate body"),req.pipe(stream);break;case"gzip":stream=zlib.createGunzip(),debug("gunzip body"),req.pipe(stream);break;case"identity":(stream=req).length=length;break;default:throw createError(415,'unsupported content encoding "'+encoding+'"',{encoding,type:"encoding.unsupported"})}return stream}module2.exports=read,__name(read,"read"),__name(contentstream,"contentstream")},8714:(module2,__unused_webpack_exports2,__webpack_require__2)=>{"use strict";var bytes=__webpack_require__2(49974),contentType=__webpack_require__2(69065),createError=__webpack_require__2(41347),debug=__webpack_require__2(44041)("body-parser:json"),read=__webpack_require__2(76421),typeis=__webpack_require__2(69820);module2.exports=json;var FIRST_CHAR_REGEXP=/^[\x20\x09\x0a\x0d]*(.)/;function json(options){var opts=options||{},limit="number"!=typeof opts.limit?bytes.parse(opts.limit||"100kb"):opts.limit,inflate=!1!==opts.inflate,reviver=opts.reviver,strict=!1!==opts.strict,type=opts.type||"application/json",verify=opts.verify||!1;if(!1!==verify&&"function"!=typeof verify)throw new TypeError("option verify must be function");var shouldParse="function"!=typeof type?typeChecker(type):type;function parse(body){if(0===body.length)return{};if(strict){var first=firstchar(body);if("{"!==first&&"["!==first)throw debug("strict violation"),createStrictSyntaxError(body,first)}try{return debug("parse json"),JSON.parse(body,reviver)}catch(e){throw normalizeJsonSyntaxError(e,{message:e.message,stack:e.stack})}}return __name(parse,"parse"),__name(function(req,res,next){if(req._body)return debug("body already parsed"),void next();if(req.body=req.body||{},!typeis.hasBody(req))return debug("skip empty body"),void next();if(debug("content-type %j",req.headers["content-type"]),!shouldParse(req))return debug("skip parsing"),void next();var charset=getCharset(req)||"utf-8";if("utf-"!==charset.substr(0,4))return debug("invalid charset"),void next(createError(415,'unsupported charset "'+charset.toUpperCase()+'"',{charset,type:"charset.unsupported"}));read(req,res,next,parse,debug,{encoding:charset,inflate,limit,verify})},"jsonParser")}function createStrictSyntaxError(str,char){var index=str.indexOf(char),partial=str.substring(0,index)+"#";try{throw JSON.parse(partial),new SyntaxError("strict violation")}catch(e){return normalizeJsonS
A server error has occurred.
node exited with 1 code.
connect ECONNREFUSED 127.0.0.1:56683

🌍 Your Environment





     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 13.0.3
Node: 16.13.0
Package Manager: npm 8.1.0
OS: darwin x64

Angular CLI: 13.1.2
Node: 16.13.1
Package Manager: npm 8.1.2
OS: darwin x64

Angular: 13.1.1
... animations, cdk, common, compiler, compiler-cli, core, forms
... language-service, material, platform-browser
... platform-browser-dynamic, router, youtube-player

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1301.2
@angular-devkit/build-angular   13.1.2
@angular-devkit/core            13.1.2
@angular-devkit/schematics      13.1.2
@angular/cli                    13.1.2
@nguniversal/builders           13.0.1
@nguniversal/express-engine     13.0.1
@schematics/angular             13.1.2
rxjs                            7.5.2
typescript                      4.4.4

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
mlbichecommented, Jan 11, 2022

Here is the whole output when I run npm run dev:ssr :

> ng run projet_name:serve-ssr

****************************************************************************************
This is a simple server for use in testing or debugging Angular applications locally.
It hasn't been reviewed for security issues.

DON'T USE IT FOR PRODUCTION!
****************************************************************************************
✔ Browser application bundle generation complete.
✔ Index html generation complete.

[... List Initial Chunk Files and Lazy Chunk Files...]

Build at: 2022-01-11T09:53:13.147Z - Hash: c86e10d2da330602 - Time: 206907ms
✔ Server application bundle generation complete.

[... List Initial Chunk Files and Lazy Chunk Files...]

Build at: 2022-01-11T09:53:32.117Z - Hash: 45e40d0663a59328 - Time: 225894ms

Compiled successfully.
/Users/thibaud/Documents/Programmation/Humanroads/gps/dist/gps/server/main.js:1
var __defProp=Object.defineProperty,__name=(target,value)=>__defProp(target,"name",{value,configurable:!0});(()=>{var __webpack_modules__={91462:(__unused_webpack_module,__webpack_exports__2,__webpack_require__2)=>{"use strict";__webpack_require__2.d(__webpack_exports__2,{qS:()=>AppRouting,_2:()=>PROFILE_ROUTE,$k:()=>ROADMAPS_ROUTE,j6:()=>SCHOOL_ROUTE,ol:()=>SITUATION_ROUTE});var router=__webpack_require__2(52816),route_urls=__webpack_require__2(57359),app_route_urls=__webpack_require__2(54335),application_and_auth_guard=__webpack_require__2(31668),application_guard=__webpack_require__2(87978),product=__webpack_require__2(6120),core=__webpack_require__2(3184),application_context_service=__webpack_require__2(809);class ConnectHomeToTimelineGuard{constructor(context,router2){this.context=context,this.router=router2}canActivate(){return this.context.product!==product.x.Connect||this.router.parseUrl(`/${app_route_urls.D.TIMELINE}`)}}__name(ConnectHomeToTimelineGuard,"ConnectHomeToTimelineGuard"),ConnectHomeToTimelineGuard.\u0275fac=__name(function(t){return new(t||ConnectHomeToTimelineGuard)(core.LFG(application_context_service.Z),core.LFG(router.F0))},"ConnectHomeToTimelineGuard_Factory"),ConnectHomeToTimelineGuard.\u0275prov=core.Yz7({token:ConnectHomeToTimelineGuard,factory:ConnectHomeToTimelineGuard.\u0275fac,providedIn:"root"});var adventure_query_string_config=__webpack_require__2(87181),application_name=__webpack_require__2(70597),error_codes=__webpack_require__2(24417),instance_dto=__webpack_require__2(93932),cjs=__webpack_require__2(26469),operators=__webpack_require__2(61755),adventure_service=__webpack_require__2(88311),mail_client=__webpack_require__2(21399),origin_resolver=__webpack_require__2(56241),popup_api_service=__webpack_require__2(7959),situation_resolver=__webpack_require__2(15323),ngx_translate_core=__webpack_require__2(87514);class PopupGuard{constructor(adventureService,context,mailClient,originResolver,popupApiService,router2,situationResolver,translateService){this.adventureService=adventureService,this.context=context,this.mailClient=mailClient,this.originResolver=originResolver,this.popupApiService=popupApiService,this.router=router2,this.situationResolver=situationResolver,this.translateService=translateService}canActivate(next){if(this.context.applicationName!==application_name.z.Popup)return!0;const situation=this.situationResolver.resolve(next),lang=next.queryParams[adventure_query_string_config.s0]||this.translateService.getBrowserLang();return next.queryParams[adventure_query_string_config.rA]?(this.popupApiService.handleUserId(next),this.originResolver.resolve(next).pipe((0,operators.zg)(o=>this.adventureService.createInstanceFromWaypoint(new instance_dto.k(this.context.applicationName,situation,o))),(0,operators.UI)(instance=>this.router.navigateByUrl(`/${app_route_urls.D.ADVENTURE_MAP(instance.id)}`).then(()=>(0,cjs.firstValueFrom)(this.translateService.use(lang)))),(0,operators.UI)(()=>!0),(0,operators.KQ)(err2=>this.mailClient.sendErrorBySlack(this.context.applicationName,err2.message).pipe((0,operators.hZ)(this.router.parseUrl(`/${app_route_urls.D.ERROR(error_codes.S.ERROR_404)}`)))))):this.router.parseUrl(`/${app_route_urls.D.ERROR(error_codes.S.ERROR_404)}`)}}__name(PopupGuard,"PopupGuard"),PopupGuard.\u0275fac=__name(function(t){return new(t||PopupGuard)(core.LFG(adventure_service.D),core.LFG(application_context_service.Z),core.LFG(mail_client.I),core.LFG(origin_resolver.O),core.LFG(popup_api_service.b),core.LFG(router.F0),core.LFG(situation_resolver.Y),core.LFG(ngx_translate_core.sK))},"PopupGuard_Factory"),PopupGuard.\u0275prov=core.Yz7({token:PopupGuard,factory:PopupGuard.\u0275fac,providedIn:"root"});var auth_service=__webpack_require__2(76352);class SSOAuthGuard{constructor(authService,router2){this.authService=authService,this.router=router2}canActivate(route){const{user,token}=route.queryParams;return!user||!token||this.authService.loginFromSSO(user,token).pipe((0,operators.UI)(success=>success?this.router.createUrlTree([],{queryParams:{user:null,token:null},queryParamsHandling:"merge"}):this.router.parseUrl(`/${app_route_urls.D.ERROR(error_codes.S.ERROR_401)}`)))}}__name(SSOAuthGuard,"SSOAuthGuard"),SSOAuthGuard.\u0275fac=__name(function(t){return new(t||SSOAuthGuard)(core.LFG(auth_service.e),core.LFG(router.F0))},"SSOAuthGuard_Factory"),SSOAuthGuard.\u0275prov=core.Yz7({token:SSOAuthGuard,factory:SSOAuthGuard.\u0275fac,providedIn:"root"});class AdventureRedirectionGuard{constructor(router2){this.router=router2}canActivate(route){return this.router.createUrlTree([`/${app_route_urls.D.INTENTIONS}`],{queryParams:route.queryParams})}}__name(AdventureRedirectionGuard,"AdventureRedirectionGuard"),AdventureRedirectionGuard.\u0275fac=__name(function(t){return new(t||AdventureRedirectionGuard)(core.LFG(router.F0))},"AdventureRedirectionGuard_Factory"),AdventureRedirectionGuard.\u0275prov=core.Yz7({token:AdventureRedirectionGuard,factory:AdventureRedirectionGuard.\u0275fac,providedIn:"root"});var intentions_component=__webpack_require__2(50495);const routes=[{path:app_route_urls.D.ADVENTURE,pathMatch:"full",canActivate:[AdventureRedirectionGuard],component:intentions_component.a},{path:app_route_urls.D.ADVENTURE_MAP(":id"),loadChildren:()=>__webpack_require__2.e(683).then(__webpack_require__2.bind(__webpack_require__2,10683)).then(module2=>module2.AdventureMapPageModule)},{path:app_route_urls.D.ADVENTURE_ITINERARY(":id"),loadChildren:()=>__webpack_require__2.e(949).then(__webpack_require__2.bind(__webpack_require__2,51949)).then(module2=>module2.AdventureItineraryPageModule)},{path:app_route_urls.D.ADVENTURE_ROADMAP(":id"),loadChildren:()=>__webpack_require__2.e(805).then(__webpack_require__2.bind(__webpack_require__2,98805)).then(module2=>module2.AdventureRoadmapPageModule)}];class AdventureRouting{}__name(AdventureRouting,"AdventureRouting"),AdventureRouting.\u0275fac=__name(function(t){return new(t||AdventureRouting)},"AdventureRouting_Factory"),AdventureRouting.\u0275mod=core.oAB({type:AdventureRouting}),AdventureRouting.\u0275inj=core.cJS({imports:[[router.Bz.forChild(routes)],router.Bz]});const intentions_routing_routes=[{path:app_route_urls.D.INTENTIONS,pathMatch:"full",loadChildren:()=>__webpack_require__2.e(182).then(__webpack_require__2.bind(__webpack_require__2,25182)).then(module2=>module2.IntentionsPageModule)},{path:app_route_urls.D.INTENTIONS_INTERNSHIP,loadChildren:()=>__webpack_require__2.e(273).then(__webpack_require__2.bind(__webpack_require__2,45273)).then(module2=>module2.IntentionsInternshipPageModule),data:{forbiddenProducts:[product.x.Explore,product.x.Show]},canActivate:[application_and_auth_guard.q]}];class IntentionsRouting{}__name(IntentionsRouting,"IntentionsRouting"),IntentionsRouting.\u0275fac=__name(function(t){return new(t||IntentionsRouting)},"IntentionsRouting_Factory"),IntentionsRouting.\u0275mod=core.oAB({type:IntentionsRouting}),IntentionsRouting.\u0275inj=core.cJS({imports:[[router.Bz.forChild(intentions_routing_routes)],router.Bz]});var rewards_routing=__webpack_require__2(24003);const timeline_routing_routes=[{path:app_route_urls.D.TIMELINE,loadChildren:()=>__webpack_require__2.e(472).then(__webpack_require__2.bind(__webpack_require__2,56472)).then(module2=>module2.TimelinePageModule),data:{title:"timeline.headline",forbiddenProducts:[product.x.Explore,product.x.Show]},canActivate:[application_and_auth_guard.q]},{path:app_route_urls.D.TIMELINE_LIBRARY,loadChildren:()=>__webpack_require__2.e(934).then(__webpack_require__2.bind(__webpack_require__2,18934)).then(module2=>module2.MockedTimelineLibraryPageModule),data:{forbiddenProducts:[product.x.Explore,product.x.Show]},canActivate:[application_and_auth_guard.q]}];class TimelineRouting{}__name(TimelineRouting,"TimelineRouting"),TimelineRouting.\u0275fac=__name(function(t){return new(t||TimelineRouting)},"TimelineRouting_Factory"),TimelineRouting.\u0275mod=core.oAB({type:TimelineRouting}),TimelineRouting.\u0275inj=core.cJS({imports:[[router.Bz.forChild(timeline_routing_routes)],router.Bz]});const HOME_ROUTE={path:"",loadChildren:()=>
A server error has occurred.
node exited with 1 code.
connect ECONNREFUSED 127.0.0.1:65121

I have also updated the Angular version in my initial post

0reactions
angular-automatic-lock-bot[bot]commented, Oct 16, 2022

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

Angular Universal dev:ssr works fine but serve:ssr shows .js
When I use the Angular Universal dev:ssr script to test the performance, ... if any error occur during server start up it broken...
Read more >
Logging and error management best practices in SSR apps
Handle errors and log them gracefully in your next web app with these best practice guidelines with examples using Next.js and Nuxt.js.
Read more >
Angular Universal: real app problems - InDepth.Dev
SSR issues in Angular · 1. Infinite page loading · 2. Lack of cache out of the box · 3. Server errors of...
Read more >
Troubleshoot a Reporting Services installation - SQL Server ...
You see an error message indicating the URL is not configured · A report server URL is not configured. Use the SSRS Integration...
Read more >
Best Practices for 5xx HTTP Response Codes - AT&T Developer
This error occurs when the server is unable to handle requests due to a temporary overload or due to the server being temporarily...
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