Universal: Angular6: No NgModule metadata found for '[object Object]'

Created on 11 Jun 2018  路  10Comments  路  Source: angular/universal

Hello. Updated my portfolio to Angular6 but got stuck with SSR. I have my code online (https://github.com/nekkon/portfolio)

Everything gets built and runs properly without any errors. Even when I run serve:ssr. But, when I visit http://localhost:3000 I get the error below:

Node Express server listening on http://localhost:3000
Error: No NgModule metadata found for '[object Object]'.
    at NgModuleResolver.resolve (/nekkon/nekkon/Desktop/projects/portfolio/dist/server.js:49357:23)
    at CompileMetadataResolver.getNgModuleMetadata (/nekkon/nekkon/Desktop/projects/portfolio/dist/server.js:47994:43)
    at JitCompiler._loadModules (/nekkon/nekkon/Desktop/projects/portfolio/dist/server.js:60132:51)
    at JitCompiler._compileModuleAndComponents (/nekkon/nekkon/Desktop/projects/portfolio/dist/server.js:60113:36)
    at JitCompiler.compileModuleAsync (/nekkon/nekkon/Desktop/projects/portfolio/dist/server.js:60073:37)
    at CompilerImpl.compileModuleAsync (/nekkon/nekkon/Desktop/projects/portfolio/dist/server.js:79885:31)
    at /nekkon/nekkon/Desktop/projects/portfolio/dist/server.js:37289:25
    at new ZoneAwarePromise (/nekkon/nekkon/Desktop/projects/portfolio/dist/server.js:1027:29)
    at getFactory (/nekkon/nekkon/Desktop/projects/portfolio/dist/server.js:37275:12)
    at View.engine (/nekkon/nekkon/Desktop/projects/portfolio/dist/server.js:37254:13)
Angular: 6.0.4
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router
... service-worker

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.8
@angular-devkit/build-angular     0.6.8
@angular-devkit/build-optimizer   0.6.8
@angular-devkit/core              0.6.8
@angular-devkit/schematics        0.6.8
@angular/cdk                      6.2.1
@angular/cli                      6.0.8
@angular/flex-layout              6.0.0-beta.16
@angular/material                 6.2.1
@ngtools/webpack                  6.0.8
@schematics/angular               0.6.8
@schematics/update                0.6.8
rxjs                              6.2.0
typescript                        2.7.2
webpack                           4.12.0

Any idea what is causing this?

Most helpful comment

I have the same issue. I tried to use suggested config, but this did not solve the issue.

All 10 comments

Hey guys. Problem was in the angular.json file. Was based on a previous version. Not sure what exactly was causing it, but changing it to the example in universal starter fixed the problem. I've seen others having the same issue (https://stackoverflow.com/questions/50477712/error-no-ngmodule-metadata-found-for-object-object/50807963#50807963). I include a correct angular.json to help people that have the same problem:

{
    "$schema": "./node_modules/@angular-devkit/core/src/workspace/workspace-schema.json",
    "version": 1,
    "newProjectRoot": "projects",
    "projects": {
        "portfolio": {
            "root": "",
            "projectType": "application",
            "architect": {
                "build": {
                    "builder": "@angular-devkit/build-angular:browser",
                    "options": {
                        "outputPath": "dist/browser",
                        "index": "src/index.html",
                        "main": "src/main.ts",
                        "tsConfig": "src/tsconfig.app.json",
                        "polyfills": "src/polyfills.ts",
                        "assets": [{
                                "glob": "**/*",
                                "input": "src/assets",
                                "output": "/assets"
                            },
                            {
                                "glob": "favicon.ico",
                                "input": "src",
                                "output": "/"
                            }
                        ],
                        "styles": [
                            "src/app/app.styles.scss"
                        ],
                        "scripts": []
                    },
                    "configurations": {
                        "production": {
                            "optimization": true,
                            "outputHashing": "all",
                            "sourceMap": false,
                            "extractCss": true,
                            "namedChunks": false,
                            "aot": true,
                            "extractLicenses": true,
                            "vendorChunk": false,
                            "buildOptimizer": true,
                            "fileReplacements": [{
                                "replace": "src/environments/environment.ts",
                                "with": "src/environments/environment.prod.ts"
                            }]
                        }
                    }
                },
                "serve": {
                    "builder": "@angular-devkit/build-angular:dev-server",
                    "options": {
                        "browserTarget": "portfolio:build"
                    },
                    "configurations": {
                        "production": {
                            "browserTarget": "portfolio:build:production"
                        }
                    }
                },
                "extract-i18n": {
                    "builder": "@angular-devkit/build-angular:extract-i18n",
                    "options": {
                        "browserTarget": "portfolio:build"
                    }
                },
                "test": {
                    "builder": "@angular-devkit/build-angular:karma",
                    "options": {
                        "main": "src/test.ts",
                        "karmaConfig": "./karma.conf.js",
                        "polyfills": "src/polyfills.ts",
                        "tsConfig": "src/tsconfig.spec.json",
                        "scripts": [],
                        "styles": [
                            "src/styles.css"
                        ],
                        "assets": [{
                                "glob": "**/*",
                                "input": "src/assets",
                                "output": "/assets"
                            },
                            {
                                "glob": "favicon.ico",
                                "input": "src",
                                "output": "/"
                            }
                        ]
                    }
                },
                "lint": {
                    "builder": "@angular-devkit/build-angular:tslint",
                    "options": {
                        "tsConfig": [
                            "src/tsconfig.app.json"
                        ],
                        "exclude": [
                            "**/node_modules/**"
                        ]
                    }
                },
                "server": {
                    "builder": "@angular-devkit/build-angular:server",
                    "options": {
                        "outputPath": "dist/server",
                        "main": "src/main.server.ts",
                        "tsConfig": "src/tsconfig.server.json"
                    },
                    "configurations": {
                        "production": {
                            "fileReplacements": [{
                                "replace": "src/environments/environment.ts",
                                "with": "src/environments/environment.prod.ts"
                            }]
                        }
                    }
                }
            }
        },
        "portfolio-e2e": {
            "root": "",
            "projectType": "application",
            "cli": {},
            "schematics": {},
            "architect": {
                "e2e": {
                    "builder": "@angular-devkit/build-angular:protractor",
                    "options": {
                        "protractorConfig": "./protractor.conf.js",
                        "devServerTarget": "portfolio:serve"
                    }
                },
                "lint": {
                    "builder": "@angular-devkit/build-angular:tslint",
                    "options": {
                        "tsConfig": [],
                        "exclude": [
                            "**/node_modules/**"
                        ]
                    }
                }
            }
        }
    },
    "cli": {},
    "schematics": {
        "@schematics/angular:class": {
            "spec": false
        },
        "@schematics/angular:component": {
            "spec": false,
            "inlineStyle": true,
            "inlineTemplate": true,
            "prefix": "app",
            "styleext": "css"
        },
        "@schematics/angular:directive": {
            "spec": false,
            "prefix": "app"
        },
        "@schematics/angular:guard": {
            "spec": false
        },
        "@schematics/angular:module": {
            "spec": false
        },
        "@schematics/angular:pipe": {
            "spec": false
        },
        "@schematics/angular:service": {
            "spec": false
        }
    }
}

I reopened the issue cause I have seen others have the same problem. It will be better if this was investigated and solved.

I have the same issue. I tried to use suggested config, but this did not solve the issue.

@nekkon what changes you add in the angular.json file for fix this issue.
because I have the same problem and can not find a solution

Hey guys. If you see my last commit in my portfolio repo you can see I made various changes that could have fixed this problem. After repeating each change 1 by 1 I found out that the error went away and everything started working fine after setting the server in angular.json as:

"server": {
          "builder": "@angular-devkit/build-angular:server",
          "options": {
            "outputPath": "dist/server",
            "main": "src/main.server.ts",
            "tsConfig": "src/tsconfig.server.json"
          },
          "configurations": {
            "production": {
              "fileReplacements": [{
                "replace": "src/environments/environment.ts",
                "with": "src/environments/environment.prod.ts"
              }]
            }
          }

Hey guys. I have same error but I am using angular 5 with:

Angular CLI: 1.7.4
Node: 8.9.4
OS: linux x64
Angular: 5.2.11
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router

@angular/cli: 1.7.4
@angular/flex-layout: 2.0.0-beta.12
@angular-devkit/build-optimizer: 0.3.2
@angular-devkit/core: 0.3.2
@angular-devkit/schematics: 0.3.2
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.2
@schematics/angular: 0.3.2
@schematics/package-update: 0.3.2
typescript: 2.5.3
webpack: 3.11.0

@nekkon I read source code of your portfolio using Angular 5 and tried to do the same to my project but I still have this error. Do you have any suggestions?

Since @nekkon fixed their original issue, we are closing this. If others are experiencing issues that can't be solved by this fix, please open a separate issue.

Hey, I'm my case I was codeing this way in angular.json:

"server": { "builder": "@angular-devkit/build-angular:server", "options": { "outputPath": "dist/server", "main": "src/main.server.ts", "tsConfig": "src/tsconfig.server.json" }, "configurations": { "production": { "fileReplacements": [ { "replace": "src/environments/environment.ts", "with": "src/environments/environment.prod.ts" } ], "outputHashing": "none", "bundleDependencies": "all" } } }

When I delete "outputHashing": "none" and "bundleDependencies": "all", fix the issue.

"server": { "builder": "@angular-devkit/build-angular:server", "options": { "outputPath": "dist/server", "main": "src/main.server.ts", "tsConfig": "src/tsconfig.server.json" }, "configurations": { "production": { "fileReplacements": [ { "replace": "src/environments/environment.ts", "with": "src/environments/environment.prod.ts" } ] } } }

I've tried both solutions and neither worked, does anyone have any clue how to fix it?

Node Express server listening on http://localhost:4000
Error: No NgModule metadata found for '[object Object]'

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