0
votes

I'm trying to test Firebase Cloud Functions locally. I have a cloud function that handles Stripe charges (followed this example https://enappd.com/blog/ionic-4-stripe-payment-integration-with-firebase-for-apps-and-pwa/17/). When I run 'firebase serve' or even 'firebase deploy', I get the following error...

Error: Cannot find module './src/index'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/Users/joesmith/Projects/Mobile/myapp/functions/node_modules/protobufjs/index.js:4:18)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
⚠  We were unable to load your functions code. (see above)

Here's my package.json

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase serve --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "8"
  },
  "dependencies": {
    "firebase": "7.14.0",
    "firebase-admin": "^8.6.0",
    "firebase-functions": "^3.6.0",
    "geofire": "^4.1.2",
    "stripe": "^8.39.2"
  },
  "devDependencies": {
    "eslint": "^5.12.0",
    "eslint-plugin-promise": "^4.0.1",
    "firebase-functions-test": "^0.2.0"
  },
  "private": true
}

Thanks.

1
It looks like you're missing a main in package.json. You should point that to your source code's index file, e.g. "main": "index.js". - Michael Bleigh
Thanks. I added main to it, but the error's still there. From the error trace, it seems to do with "protobufjs", whatever that is. - Obi
Try deleting node_modules and package-lock.json and running npm install again. - Michael Bleigh
Thanks, @MichaelBleigh. That worked! You're a genius. - Obi

1 Answers

3
votes

Thanks to @MichaelBleigh, I fixed it by deleting node_modules and package-lock.json and then running firebase serve again.