条纹导致 Firebase 中的部署错误(网络)

时间:2021-06-22 18:42:58

标签: javascript node.js firebase npm stripe-payments

我刚刚在我的 firebase 函数 index.js 中添加了条纹:

const stripe = require('stripe')('key');

以及结帐会话的创建者功能:

    exports.createCheckoutSession = functions.https.onCall(async(data, context) => {
    const YOUR_DOMAIN = 'http://localhost:5000';
    const session = await stripe.checkout.sessions.create({
        payment_method_types: ['card'],
        metadata: { firebase_uid: context.auth.uid },
        line_items: [{
            price_data: {
                currency: 'usd',
                product_data: {
                    name: 'Stubborn Attachments',
                    images: ['https://i.imgur.com/EHyR2nP.png'],
                },
                unit_amount: 2000,
            },
            quantity: 1,
        }, ],
        mode: 'payment',
        success_url: `${YOUR_DOMAIN}/page/shop/shop.html`,
        cancel_url: `${YOUR_DOMAIN}/page/shop/shop.html`,
    });
    return session.id
})

由于我使用了条带,因此在部署 (firebase deploy --only functions) 时总是会出错

我收到此错误:Error: Functions did not deploy properly. 我已经阅读了这个 stackoverflow 问题,但没有帮助:Error: Functions did not deploy properly

我还注释了 const stripe = require('stripe')('key');,然后我就可以部署了。所以我认为是stripe包的错误。我还再次运行了 npm i stripe,但没有帮助。

我的 package.js:

{
    "name": "functions",
    "description": "Cloud Functions for Firebase",
    "scripts": {
        "lint": "eslint .",
        "serve": "firebase emulators:start --only functions",
        "shell": "firebase functions:shell",
        "start": "npm run shell",
        "deploy": "firebase deploy --only functions",
        "logs": "firebase functions:log"
    },
    "engines": {
        "node": "14"
    },
    "main": "index.js",
    "dependencies": {
        "firebase-admin": "^9.2.0",
        "firebase-functions": "^3.11.0"
    },
    "devDependencies": {
        "eslint": "^7.6.0",
        "eslint-config-google": "^0.14.0",
        "firebase-functions-test": "^0.2.0",
        "stripe": "^8.156.0"
    },
    "private": true
}

我希望你能帮助我。感谢您的时间!

编辑: 我的版本: npm:7.18.1 节点:14.16.0 火力基地管理员:9.6.0 火力基地功能测试:0.2.3 燃烧功能:3.13.2 条纹:8.156.0

1 个答案:

答案 0 :(得分:0)

我刚刚发现我的错误是什么。在 package.js 中,"stripe": "^8.156.0" 需要位于依赖项中,而不是 devDependencies。像这样:

{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
    "lint": "eslint .",
    "serve": "firebase emulators:start --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
},
"engines": {
    "node": "14"
},
"main": "index.js",
"dependencies": {
    "firebase-admin": "^9.2.0",
    "firebase-functions": "^3.11.0",
    "stripe": "^8.156.0"
},
"devDependencies": {
    "eslint": "^7.6.0",
    "eslint-config-google": "^0.14.0",
    "firebase-functions-test": "^0.2.0"
},
"private": true

}