1

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.

4
  • 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". Commented Apr 14, 2020 at 16:41
  • 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. Commented Apr 14, 2020 at 19:17
  • 2
    Try deleting node_modules and package-lock.json and running npm install again. Commented Apr 14, 2020 at 20:56
  • Thanks, @MichaelBleigh. That worked! You're a genius. Commented Apr 14, 2020 at 21:39

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.