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

37 replies
Last 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:

  1. Set the PORT environment variable before running the dev command:

    PORT=3000 npm run dev
  2. Create a .env.local file in your project root and define the PORT:

    PORT=3000
  3. Modify the package.json script to hardcode a port instead of using the variable:

    "dev": "concurrently \"next --port 3000\" \"cd studio && sanity start\"",

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

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.

Was this answer helpful?