Watch a live product demo 👀 See how Sanity powers richer commerce experiences

Next.js E-commerce Example Issue - UnhandledPromiseRejectionWarning: Error: Option requires argument: --port

32 replies
Last updated: Jan 25, 2021
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.
Jan 25, 2021, 10:33 AM
The studio runs on port
, but the guide says it will run on
Jan 25, 2021, 10:38 AM
I used the “Create project” thing
Jan 25, 2021, 10:38 AM
Maybe I’m not suppose to run
npm run dev
. But I also have some issues with Vercel when using
npm start
Jan 25, 2021, 10:41 AM
I think you can pass in a port like so:
$PORT=3000 npm run dev
…but you might as well remove the --port argument together with $PORT in your package.json script!
Jan 25, 2021, 10:42 AM
the template rewrites
to localhost:3333 for you, I think that’s why in the guide it saids localhost:3000/studio
Jan 25, 2021, 10:43 AM
I’m not sure where to go from here
Jan 25, 2021, 10:48 AM
Seems like the login helped a bit. Next runs, but the studio (localhost:3000/studio) loads until I get a 5xx error
Jan 25, 2021, 11:05 AM
I also noticed
has this in it:
  "api": {
    "projectId": "placeholder",
    "dataset": "placeholder"
I tried with placeholder and with my projectId and dataset
Jan 25, 2021, 11:07 AM
Error occurred proxying <http://localhost:3333/studio> Error: connect ECONNREFUSED
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
  errno: -61,
  syscall: 'connect',
  address: '',
  port: 3333
Jan 25, 2021, 11:20 AM
looks like the studio is not running on port 3333
Jan 25, 2021, 11:21 AM
could you cd into /studio &amp; run
sanity start
Jan 25, 2021, 11:21 AM
Yeah, the studio runs fine that way
Jan 25, 2021, 11:24 AM
cool, you should be able to go to localhost:3000/studio now I think
Jan 25, 2021, 11:24 AM
(http://localhost:3333 probably when using the standard port with
sanity start
Jan 25, 2021, 11:25 AM
Is there anyway to make it work without having two terminal windows?
Jan 25, 2021, 11:26 AM
It works if I run
sanity start
in one window and
npm start
in another
Jan 25, 2021, 11:27 AM
npm run dev
is supposedly the one that’ll run both in one window
Jan 25, 2021, 11:27 AM
npm run dev
in the root should start both your Next and Sanity development servers on localhost:3000 and localhost:3333, respectively
Jan 25, 2021, 11:27 AM
Then I get the port problem again
Jan 25, 2021, 11:28 AM
you could try
PORT=3000 npm run dev
, or just remove the whole ‘--port $PORT’ part
Jan 25, 2021, 11:29 AM
Ah, I see. I tried that earlier with the $ sign first.
Jan 25, 2021, 11:30 AM
my bad, I think I might have mistakenly left that in 😛
Jan 25, 2021, 11:31 AM
Ok, now it runs fine.
Jan 25, 2021, 11:31 AM
Thanks 🙂
Jan 25, 2021, 11:31 AM
Looks like it's missing an environment variable there. You could do as Derek suggested or create a
file in your project root folder with this content:
Jan 25, 2021, 11:31 AM
The example .env didn’t contain that variable. I also tried adding that, but it doesn’t seem to do anything
Jan 25, 2021, 11:32 AM
(Or rename
and add that variable there)
Jan 25, 2021, 11:32 AM
Sorry about the confusion, Ole, we'll update the starter to include that information 🙂
Jan 25, 2021, 11:32 AM
Jan 25, 2021, 11:37 AM
I don’t know what the
sign means, but on macOS it doesn’t seem to read it from .env with it
Jan 25, 2021, 11:37 AM
For simplicity, we should probably just adapt it to run
in dev instead, without the
    "dev": "concurrently \"next\" \"cd studio &amp;&amp; sanity start\"",
Jan 25, 2021, 11:49 AM
Updated the starter itself as well now. Thanks for the feedback, Ole - and thanks for helping out, Derek 🙌
Jan 25, 2021, 11:54 AM

Sanity– build remarkable experiences at scale

The Sanity Composable Content Cloud is the modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Related answers

Get more help in the community Slack

TopicCategoriesFeaturedRepliesLast Updated
After adding the subtitle and running this code npm run graphql-deploy It does nothingSep 15, 2020
how to limit a reference to just one entry in Studio reference input side versus the default as-many-entries-as-you-fill-in-an-array...Sep 18, 2020
Is it possible to fetch more than one "_type" using GROQ?Nov 2, 2020
I want to add a view with the Structure builder (S.view.component) where I list similar documents based on the title. What...Sep 23, 2020
Is there a structure builder example where the format of each preview for the document list is modified?Feb 3, 2021
I have an array of references to a country schema type but it always just returns NULL values for meJan 30, 2021
Hi, I need help with a query for getting the url of an image asset. Here is what I've been trying, but I only get the _ref...Dec 1, 2020
Sanity UI looks brilliant :smiley: Is something like the current date picker possible at the moment? I’m not sure if anicon...Dec 21, 2020
Hey everyone. I have been coding and may have potentially accidentally deleted something. Does anyone know how to resolve...Dec 26, 2020
Hello everyone and happy new year :raised_hands::skin-tone-2:, I have a problem with outputting Portable Text :disappointed:...Jan 1, 2021

Related contributions

Clean Next.js + Sanity app
- Template

Official(made by Sanity team)

A clean example of Next.js with embedded Sanity ready for recomposition.

Cody Olsen
Go to Clean Next.js + Sanity app

Blog with Built-in Content Editing
- Template

Official(made by Sanity team)

A Sanity-powered blog with built-in content editing and instant previews.

Go to Blog with Built-in Content Editing