Search code examples
node.jsfirebasegoogle-cloud-platformgoogle-cloud-functionsfirebase-tools

Firebase error when deploying cloud function: Cannot find module ...firebase-functions\lib\bin\firebase-functions.js'


I'm facing this issue and I don't know how to resolve it. I'd like to deploy a Firebase hosting app which use cloud functions from Firebase.

so here is the logs

firebase deploy --only functions:helloWorld

=== Deploying to 'qdconstruction-frontend'...

i  deploying functions
i  functions: preparing codebase default for deployment
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
i  artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
+  functions: required API cloudfunctions.googleapis.com is enabled
+  artifactregistry: required API artifactregistry.googleapis.com is enabled
+  functions: required API cloudbuild.googleapis.com is enabled
i  functions: Loading and analyzing source code for codebase default to determine what to deploy
'D\my-project\functions\node_modules\.bin\' is not recognized as an internal or external command,
operable program or batch file.

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

Error: Cannot find module 'D:\theparentdirofmy-project\firebase-functions\lib\bin\firebase-functions.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1134:15)
    at Module._load (node:internal/modules/cjs/loader:975:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12)
    at node:internal/main/run_main_module:28:49 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v18.19.1

my function folder contains the default function in the index.js I did npm install in this folder too.

const {onRequest} = require("firebase-functions/v2/https");
const logger = require("firebase-functions/logger");


exports.helloWorld = onRequest((request, response) => {
  logger.info("Hello logs!", {structuredData: true});
  response.send("Hello from Firebase!");
});

So I tried to change my node version, I tried to start a new project with only functions (which works). I'm using nvm manager to manage node. No problem with other node usage before. so I'm wondering if it's possible to set firebase hosting and cloud functions in the same project? I think it should be since the firebase init propose multiple services from Firebase.. It's a new project so I'm using last versions generally. I also noticed that

D\my-project\functions\node_modules.bin' is not recognized ... Error: Cannot find module 'D:\theparentdirofmy-project\

the path are not the same. Is it normal?


Solution

  • jesus I found the problem. My parent folder has a '&' character which cause the problem.