stripe-firebase-extensions: firestore-stripe-payments v0.0.4 has error: SyntaxError: Unexpected token 'export'

Bug report

Describe the bug

in Next.js

import {
  createCheckoutSession,
  getStripePayments,
} from '@stripe/firestore-stripe-payments';

// some code ...

👇🏻

SyntaxError: Unexpected token 'export'

This error happened while generating the page. Any console logs will be displayed in the terminal window.
Call Stack
<unknown>
/Users/nino/Projects/simple-flock/node_modules/ (stripe/firestore-stripe-payments/lib/index.js (16)
Object.compileFunction
node:vm (352:18)
wrapSafe
node:internal/modules/cjs/loader (1025:15)
Module._compile
node:internal/modules/cjs/loader (1059:27)
Object.Module._extensions..js
node:internal/modules/cjs/loader (1147:10)
Module.load
node:internal/modules/cjs/loader (975:32)
Function.Module._load
node:internal/modules/cjs/loader (822:12)
Module.require
node:internal/modules/cjs/loader (999:19)
require
node:internal/modules/cjs/helpers (102:18)
Object.@stripe/firestore-stripe-payments
file:///Users/nino/Projects/simple-flock/.next/server/pages/mypage.js (197:18)
__webpack_require__
file:///Users/nino/Projects/simple-flock/.next/server/webpack-runtime.js (33:42)

v0.0.3 is work ✅ v0.0.4 has error 🚫


Thank you for your support 😃

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 10
  • Comments: 18 (2 by maintainers)

Most upvoted comments

For those experiencing this bug, you can add this to your next.config.js:

const nextConfig = {
  // ...
  transpilePackages: ["@stripe/firestore-stripe-payments"],
};

Edit: You will need to restart the server and might still get an error in the console, but the package should still work normally.

I was able to reproduce this issue on all versions v0.0.3 to v0.0.6 with a next-js starter project.

├── @stripe/firestore-stripe-payments@0.0.3
├── next@12.0.10
├── react@17.0.2
└── react-dom@17.0.2

Couldn’t find any specific config changes that could cause this in firestore-stripe-payments codebase. However, I was able to fix the error by adding the following to next.config.js.

const withTM = require('next-transpile-modules')([
  '@stripe/firestore-stripe-payments'
]);

/** @type {import('next').NextConfig} */
module.exports = withTM({
  reactStrictMode: true,
});

Let us know if using next-transpile-modules in next.config.js could be a workaround until we find the root cause for this issue. Thanks!

FYI: @lemuel-stripe @cjavilla-stripe

With the sdk update, you need to change the workaround to :

const nextConfig = {
  ...
  transpilePackages: ["@invertase/firestore-stripe-payments"],
};

Same issue here, starting a new project that only has npm i firebase and npm i @stripe/firestore-stripe-payments with import getStripePayments from '@stripe/firestore-stripe-payments' and running the file with node <filename>.js is enough to reproduce the issue.