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-modulesStar
Discord
online
Get help straight from the Payload team with an Enterprise License.