Error Angular Universal running serve:ssr

[REQUIRED] Describe your environment

  • Operating System version: Windows 10
  • Firebase SDK version: 6.3.1
  • Firebase Product: database
  • Angular version: 8.1.2

[REQUIRED] Describe the problem

I’ve added firebase on a new Angular project and it works fine when I run ng serve. I can build the project for SSR without problem running the command npm run build:ssr. But when I run npm run serve:ssr I get the following error:

myapp@0.0.0 serve:ssr C:\Develop\js\projects\myapp
node dist/server

C:\Develop\js\projects\myapp\dist\server\main.js:126258
        throw new Error("package.json does not exist at " + package_json_path);
        ^

Error: package.json does not exist at C:\Develop\js\projects\myapp\dist\package.json
    at Object.PsoT.exports.find (C:\Develop\js\projects\myapp\dist\server\main.js:126258:15)
    at Object.wPNL (C:\Develop\js\projects\myapp\dist\server\main.js:176077:12)
    at __webpack_require__ (C:\Develop\js\projects\myapp\dist\server\main.js:20:30)
    at Object.XpdW (C:\Develop\js\projects\myapp\dist\server\main.js:142482:12)
    at __webpack_require__ (C:\Develop\js\projects\myapp\dist\server\main.js:20:30)
    at Object.g1pB (C:\Develop\js\projects\myapp\dist\server\main.js:165365:27)
    at __webpack_require__ (C:\Develop\js\projects\myapp\dist\server\main.js:20:30)
    at Object.Ou8q (C:\Develop\js\projects\myapp\dist\server\main.js:123737:14)
    at __webpack_require__ (C:\Develop\js\projects\myapp\dist\server\main.js:20:30)
    at Object.BYZf (C:\Develop\js\projects\myapp\dist\server\main.js:89971:12)

Steps to reproduce:

  • Create a new Angular app
  • Install firebase: npm install firebase –save
  • Use firebase in the default AppComponent (like in the following section)
  • Install nguniversal: ng add @nguniversal/express-engine –clientProject myapp
  • Build the project for ssr: npm run build:ssr
  • Run the project with ssr: run serve:ssr

Relevant Code:

export class AppComponent {

  constructor() {

    const app = firebase.initializeApp(environment.firebase);
    const db = firebase.firestore(app);

    db.collection('articles').get().then((querySnapshot) => {
      querySnapshot.forEach((doc) => {
          console.log(`${doc.id} => ${doc.data()}`);
      });
    });
  }
}

1 possible answer(s) on “Error Angular Universal running serve:ssr

  1. I have found that the firebase-js-sdk cannot be used with any/many ssr enabled frameworks. We have attempted to use it with Angular, Nextjs, and Fusion.js.
    > Build error occurred { Error: Failed to load C:\Users\jrodk\Projects\joyride\node_modules\grpc\src\node\extension_binary\node-v64-win32-x64-unknown\grpc_node.node. Module did not self-register. at Object.Module._extensions..node (internal/modules/cjs/loader.js:805:18) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) at Module.require (internal/modules/cjs/loader.js:690:17) at require (internal/modules/cjs/helpers.js:25:18) at Object.<anonymous> (C:\Users\jrodk\Projects\joyride\node_modules\grpc\src\grpc_extension.js:32:13) at Module._compile (internal/modules/cjs/loader.js:776:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10) at Module.load (internal/modules/cjs/loader.js:653:32) type: 'Error', '$error': '$error' }