Joint session with Vercel: How to build intelligent storefronts (May 15th)

Issue with setting up Next.js E-commerce example and resolving the error related to the port.

37 repliesLast updated: Nov 29, 2025

Hi, I’m trying to set up the Next.js E-commerece example but I’ve ran into an issue. I get this error in console
(node:33819) UnhandledPromiseRejectionWarning: Error: Option requires argument: --port
. In the package.json-file I see that the script
"dev": "concurrently \"next --port $PORT\" \"cd studio && sanity start\"",
is trying to use a variable called $PORT (I’m assuming), but this variable isn’t defined anywhere in the example.
AI Update

The error you're encountering is because the $PORT environment variable isn't set in your system. This is a common issue with the Next.js e-commerce example starter.

The Quick Fix:

You have a few options to resolve this:

Why This Happens:

The example assumes you'll have a PORT environment variable set, but it's not included in the starter template by default. The $PORT syntax is trying to reference this environment variable (on Unix-based systems; on Windows you'd use %PORT%).

Recommended Approach:

I'd suggest option 3 (hardcoding the port in package.json) for local development since it's the simplest and most reliable across different operating systems. Port 3000 is the standard Next.js development port. The Sanity Studio will run on its default port 3333.

If you need different ports for any reason, just change the number in the script. The important thing is that Next.js and Sanity Studio run on different ports so they don't conflict.

Show original thread
37 replies

Was this answer helpful?

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Related contributions