Description
Bug report
- Extension name: firestore-stripe-web-sdk
Describe the bug
The firestore-stripe-web-sdk module is written as an ES Module, but it has a few problems that make it invalid ESM. First, there is no "type": "module"
field in package.json
and the files do not use the .mjs
extension. Second, the relative imports need the full extension (as mentioned in TypeScript's docs), which they currently don't have.
import { getStripePayments } from "@stripe/firestore-stripe-payments";
^^^^^^^^^^^^^^^^^
SyntaxError: Named export 'getStripePayments' not found. The requested module '@stripe/firestore-stripe-payments' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from '@stripe/firestore-stripe-payments';
const { getStripePayments } = pkg;
To Reproduce
It should be reproduceable with simpler configurations (without a framework), but I faced the issue when working with SvelteKit, so the the repro is based on SvelteKit.
Steps to reproduce the behavior:
npm create svelte@latest demo-app
(choose Skeleton project for simplicity)cd demo-app
andnpm install
npm install firebase @stripe/firestore-stripe-payments @sveltejs/adapter-static
- Replace
adapter-auto
import withadapter-static
insvelte.config.js
- Add the following content to
src/routes/+page.svelte
:<script> import { getApp } from '@firebase/app'; import { getStripePayments } from '@stripe/firestore-stripe-payments'; const app = getApp(); const payments = getStripePayments(app); console.log(payments); </script>
- Add a
src/routes/+layout.js
file with justexport const prerender = true;
inside. - Run
npm run build
Expected behavior
It should work normally.
System information
- OS: Windows 10
- Browser: Chrome
- Node: v16.15.1
Additional context
Some build systems may auto-detect the module system and ignore the missing extension problem, but that doesn't make it a valid ES Module. In particular, I didn't face this issue with SvelteKit v1.0.0-next.350
, but when I updated to a recent version that requires a separate vite
config and the Vite CLI I got the error above. I'm not sure about the underlying difference between both versions.
Solution
The solution is simple:
- Add
"type": "module"
topackage.json
- Add the
.js
extension to all relative imports (even if the source files are TS)
I can submit a PR with the fixes if needed.