Demo, all content is generated
Question

Edge function deploy fails: Relative import path "stripe" not prefixed with / or ./ or ../

Solved · 351 views · asked by adebayo_t · edited

Cursor wrote an edge function for Stripe checkout like it's a Node file:

import Stripe from 'stripe'

supabase functions deploy create-checkout fails with:

error: Relative import path "stripe" not prefixed with / or ./ or ../

I ran npm install stripe in the project root, it's in package.json. What am I missing?

What I’ve tried

Tried importing from '../../node_modules/stripe', that gave a different error about require. Cursor keeps going back and forth between two versions.

Comment
Is this in supabase/functions? Then it runs on Deno, not Node. jb_supa · edited

2 answers

Marked as helpful by the asker
jb_supa · edited

Edge functions run on Deno, which doesn't look in node_modules for bare names. Use an npm: specifier:

import Stripe from 'npm:stripe@17'

const stripe = new Stripe(Deno.env.get('STRIPE_SECRET_KEY')!)

Or, to keep imports clean, add a deno.json in the function folder:

{ "imports": { "stripe": "npm:stripe@17" } }

Then import Stripe from 'stripe' works. Pin the version, otherwise a deploy months from now pulls whatever is latest. And set the key with supabase secrets set STRIPE_SECRET_KEY=..., your .env.local isn't deployed.

Comment
npm: prefix + deno.json, deployed. And yes, the secret was the next error, already set it adebayo_t · edited
gus_fullstack · edited

Tell Cursor in your rules that supabase/functions is Deno, not Node. Otherwise it keeps writing process.env and require in there.

Comment
Added to .cursorrules, it stopped using process.env in there. adebayo_t · edited