0

I ran firebase init in powershell (inbuilt vscode term) and did its thing, i selected TypeScript, and it generated the files. I also installed dependencies in the script.

However, I tried to run this code in an index.ts file and it threw the accompanied error:

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';

admin.initializeApp();

async function grantModeratorRole(email: string): Promise<void> {
    const user = await admin.auth().getUserByEmail(email);
    if (user.customClaims && (user.customClaims as any).moderator) {
        return;
    }
    return admin.auth().setCustomUserClaims(user.uid, { 
        moderator: true 
    });
}

grantModeratorRole("bearcodes@outlook.com");

(the call of the function is a test for the time being)

The error is:

node:internal/modules/cjs/loader:361
      throw err;
      ^

Error: Cannot find module 'C:\Users\bearc\Documents\WebstormProjects\SimsRedux\functions\lib\index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (node:internal/modules/cjs/loader:353:19)
    at Function.Module._findPath (node:internal/modules/cjs/loader:566:18)
    at resolveMainPath (node:internal/modules/run_main:15:25)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:73:24)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  path: 'C:\\Users\\bearc\\Documents\\WebstormProjects\\SimsRedux\\functions\\package.json',
  requestPath: 'C:\\Users\\bearc\\Documents\\WebstormProjects\\SimsRedux\\functions'
}

Thanks in advance!

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Psuedo
  • 29
  • 8

1 Answers1

0

Can you try to change your imports to this:

import * as functions from "firebase-functions";
import admin from "firebase-admin";
Tarik Huber
  • 7,061
  • 2
  • 12
  • 18