Front-end crash with Stripe package

default discord avatar
SKRY
6 months ago
1

Hello, I'm trying to use Stripe with collection hooks but as soon as I add the "new Stripe" line, payload's front-end is crashing.



In my collection file :


import Stripe from "stripe";

const stripeSecretKey = process.env.STRIPE_SECRET_KEY;
const stripe = new Stripe(stripeSecretKey, { apiVersion: "2022-11-15" });


Browser console error :


Uncaught TypeError: stripe__WEBPACK_IMPORTED_MODULE_1___default(...) is not a constructor
    at ./src/collections/Items.ts (Items.ts:6:16)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:62:1)
    at fn (hot module replacement:62:1)
    at ./src/payload.config.ts (slug.ts:22:4)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:62:1)
    at fn (hot module replacement:62:1)
    at ./node_modules/payload/dist/admin/index.js (useThumbnail.js:30:29)
    at __webpack_require__ (bootstrap:24:1)
./src/collections/Items.ts    @    Items.ts:6
__webpack_require__    @    bootstrap:24
fn    @    hot module replacement:62
fn    @    hot module replacement:62
./src/payload.config.ts    @    slug.ts:22
__webpack_require__    @    bootstrap:24
fn    @    hot module replacement:62
fn    @    hot module replacement:62
./node_modules/payload/dist/admin/index.js    @    useThumbnail.js:30
__webpack_require__    @    bootstrap:24
(anonymous)    @    startup:5
(anonymous)    @    startup:5


Okay I fixed it with this :

https://payloadcms.com/docs/admin/webpack#aliasing-server-only-modules
    Open the post
    Continue the discussion in Discord
    Like what we're doing?
    Star us on GitHub!

    Star

    Connect with the Payload Community on Discord

    Discord

    online

    Can't find what you're looking for?

    Get help straight from the Payload team with an Enterprise License.