Next.js Discord

Discord Forum

Running dev servers programmatically

Unanswered
Egyptian Mau posted this in #help-forum
Open in Discord
Egyptian MauOP
Hi everyone,

I'm trying to create a dev server programmatically using next, eg:
const app = next({ dev, hostname, port, dir });

However, I'm having a lot of trouble.

1- For whatever reason, I'm forced to add experimental.appDir in the next.config.js file of the directory the server is serving, even though, running next dev directly from the terminal suggests not to add that option.

2- After starting the server, none of the fonts/styles are being loaded, and the console spits out these errors: (see screenshots)
It almost feels like next is running an older version of dev server when launching it programmatically.

3- this is more a nice to have, but is there any way I can tell next to use turbopack when starting the server?

Is there a different configuration that applies to dev servers launch in this way? any help is appreciated!


PS: I'm very to new to next.js, so please bear with me in case this is obvious!

11 Replies

can you try updating your next.js version
wait you say error is not when normaly run
ahhh, i didn't even know you could programicly launch it without using cli (ie process.spawn)
Egyptian MauOP
You can, but It's not great, and I'm having trouble finding resources regarding this
but whats wrong with using npm scripts and putting the turbo flag there?
Egyptian MauOP
I'm building an app for which I need to run headless dev servers
headless dev server?
Egyptian MauOP
I'm writing a script that expects a next app directory path, spins up a dev server for it, and returns the url the server is running on
hmmm
Egyptian MauOP
The app is essentially a no-code editor. the editor generates next.js code.
I need the dev server to run the generated code to be able to live-preview it in the browser