Issue with setting up Next.js E-commerce example and resolving the error related to the port.
37 replies
Last updated: Jan 25, 2021
P
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 . In the package.json-file I see that the script is trying to use a variable called $PORT (I’m assuming), but this variable isn’t defined anywhere in the example.
(node:33819) UnhandledPromiseRejectionWarning: Error: Option requires argument: --port
"dev": "concurrently \"next --port $PORT\" \"cd studio && sanity start\"",
Jan 25, 2021, 10:33 AM
P
The studio runs on port
3333, but the guide says it will run on
localhost:3000/studio
Jan 25, 2021, 10:38 AM
P
I used the “Create project” thing
Jan 25, 2021, 10:38 AM
P
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
G
I think you can pass in a port like so:
…but you might as well remove the --port argument together with $PORT in your package.json script!
$PORT=3000 npm run dev
Jan 25, 2021, 10:42 AM
G
the template rewrites
/studioto localhost:3333 for you, I think that’s why in the guide it saids localhost:3000/studio
Jan 25, 2021, 10:43 AM
B
I think it assumes that you use
vercel dev
Jan 25, 2021, 10:46 AM
P
I’m not sure where to go from here
Jan 25, 2021, 10:48 AM
B
vercel loginto get a new token, then I assume you need to link it to a Vercel project?
Jan 25, 2021, 10:50 AM
B
I ran into the same confusion on how to run it when testing the project, but I had it setup on Vercel through https://create.sanity.io/
Jan 25, 2021, 10:51 AM
P
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
P
I also noticed
I tried with placeholder and with my projectId and dataset
sanity.jsonhas this in it:
"api": { "projectId": "placeholder", "dataset": "placeholder" },
Jan 25, 2021, 11:07 AM
P
Error occurred proxying <http://localhost:3333/studio> Error: connect ECONNREFUSED 127.0.0.1:3333 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) { errno: -61, code: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 3333 }
Jan 25, 2021, 11:20 AM
G
looks like the studio is not running on port 3333
Jan 25, 2021, 11:21 AM
G
could you cd into /studio & run
sanity start?
Jan 25, 2021, 11:21 AM
P
Yeah, the studio runs fine that way
Jan 25, 2021, 11:24 AM
G
cool, you should be able to go to localhost:3000/studio now I think
Jan 25, 2021, 11:24 AM
M
(http://localhost:3333 probably when using the standard port with
sanity start)
Jan 25, 2021, 11:25 AM
P
Is there anyway to make it work without having two terminal windows?
Jan 25, 2021, 11:26 AM
P
It works if I run
sanity startin one window and
npm startin another
Jan 25, 2021, 11:27 AM
G
the
npm run devis supposedly the one that’ll run both in one window
Jan 25, 2021, 11:27 AM
M
npm run devin the root should start both your Next and Sanity development servers on localhost:3000 and localhost:3333, respectively
Jan 25, 2021, 11:27 AM
P
Then I get the port problem again
Jan 25, 2021, 11:28 AM
G
you could try
PORT=3000 npm run dev, or just remove the whole ‘--port $PORT’ part
Jan 25, 2021, 11:29 AM
P
Ah, I see. I tried that earlier with the $ sign first.
Jan 25, 2021, 11:30 AM
G
my bad, I think I might have mistakenly left that in 😛
Jan 25, 2021, 11:31 AM
P
Ok, now it runs fine.
Jan 25, 2021, 11:31 AM
P
Thanks 🙂
Jan 25, 2021, 11:31 AM
M
Looks like it's missing an environment variable there. You could do as Derek suggested or create a
.envfile in your project root folder with this content:
PORT="3000"
Jan 25, 2021, 11:31 AM
P
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
M
(Or rename
.env.testto
.envand add that variable there)
Jan 25, 2021, 11:32 AM
M
Sorry about the confusion, Ole, we'll update the starter to include that information 🙂
Jan 25, 2021, 11:32 AM
P
NODE_ENV=PORTworks
Jan 25, 2021, 11:37 AM
P
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
M
For simplicity, we should probably just adapt it to run
nextin dev instead, without the
--portflag:
"dev": "concurrently \"next\" \"cd studio && sanity start\"",
Jan 25, 2021, 11:49 AM
M
Updated the starter itself as well now. Thanks for the feedback, Ole - and thanks for helping out, Derek 🙌
Jan 25, 2021, 11:54 AM
P
For simplicity, we should probably just adapt it to run
nextin dev instead, without the
--portflag:
"dev": "concurrently \"next\" \"cd studio && sanity start\"",
Jan 25, 2021, 11:49 AM
P
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
Sanity is a 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.