我正在尝试在本地测试Firebase Cloud函数。我有一个处理Stripe费用的云功能(按照这个例子https://enappd.com/blog/ionic-4-stripe-payment-integration-with-firebase-for-apps-and-pwa/17/)。当我运行"firebase serve"甚至"firebase deploy"时,我会得到以下错误。。。
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)
这是我的包.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
}
谢谢。
感谢@MichaelBleigh,我通过删除node_modules和package-lock.json并再次运行firebase serve
修复了它。