skip to Main Content

I have created a repo with angular/fire and cloud functions.
No i want to run the functions emulator, but it tells me, that index.js doesn’t exist.
But how should it exists, when i use Typescript?
In functions/src/ i have a index.ts and it should us this instead.
But when i set "main":"src/index.ts" in package.json i got this error:

Failed to load functions definition from source: FirebaseError: Failed to load functions definition from source: Failed to generate manifest from functions source: SyntaxError: Cannot use import statement outside a module

How can i fix this?

2

Answers


  1. But when i set "main":"src/index.ts" in package.json

    Bad idea

    Did you build the package before starting the emulator? It will create the index.js for you.

    Login or Signup to reply.
  2. You just need to run the npm run build command to generate the index.js file. Which will be located in the functions/lib/ folder.

    The error message is clear, that you are using the import statement in the wrong place.

    Where as the correct import is:

    import * as admin from "firebase-admin";
    admin.initializeApp();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search