question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Double server from CLI

See original GitHub issue

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
Binaries:
  Node: 16.15.1
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant packages:
  next: 12.2.1-canary.1
  eslint-config-next: 12.2.0
  react: 18.2.0
  react-dom: 18.2.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

CLI

Describe the Bug

I have app.js file in root folder.

const start = require('next/dist/cli/next-start')
start.nextStart()

It starts 2 servers at the same time. It starts dev server instead of production and overwrites contents of .next folder with files of dev server.

> node app.js
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
ready - started server on 0.0.0.0:3000, url: http://localhost:3000

Accessing localhost:3000 returns error 404

Expected Behavior

Only start production server

Link to reproduction

https://github.com/Arctomachine/reproduction-double-server

To Reproduce

  1. Run next build
  2. Run node app.js

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
QuiiBzcommented, Jul 3, 2022

I searched a bit and the issue first appeared in version 12.1.1-canary.5.

Importing next/dist/cli/next-start without calling nextStart() before this version does not start the server.

edit: It’s a regression from https://github.com/vercel/next.js/pull/34836:

When getProjectDir is called, it now also imports next/bin/next.ts, which is itself calling commands[command]().

This command should not be defined, but it fallbacks to defaultCommand, which is dev (that explains why the dev server is also started)

2nd edit: Opened a PR that fixes the issue: #38274

2reactions
Arctomachinecommented, Jul 3, 2022

require('next/dist/cli/next-start') alone already starts server and gives one output. If you try only this line, you will get fully working dev server. But in either case, with 2 outputs it starts malfunctioning dev server, while functioning production is expected.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Running multiple servers in a single command terminal instance
Each folder requires me to run a different command to run it's server in a separate command instance which is troublesome for my...
Read more >
Ssh through two servers and a user in one command line
How to go about doing in one command line the following operations? $ ssh server-one $ su - user $ ssh server-two. Of...
Read more >
Run two servers simultanually from bash script - Ask Ubuntu
and I executed using bash script.sh . Now hueserver is running but not hiveserver. A second terminal is open but with nothing in...
Read more >
5.8.2.1 Starting Multiple MySQL Instances at the Windows ...
Each server starts in the foreground (no new prompt appears until the server exits later), so you need to issue those two commands...
Read more >
Setting multiple network time servers from the command line
Add the secondary time server as the second line in /etc/ntp.conf echo "server $TimeServer2" >> /etc/ntp.conf. # Add the tertiary time ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found