Skip to content

🎥 Make videos programmatically with React

fail hard if selected port is not available

Jonny Burger63f5661b117c
diff --git a/packages/bundler/src/start-server.ts b/packages/bundler/src/start-server.ts
index b9950ccfed..6b88c61cfc 100644
--- a/packages/bundler/src/start-server.ts
+++ b/packages/bundler/src/start-server.ts
@@ -68,12 +68,20 @@ export const startServer = async (
res.sendFile(path.join(__dirname, '..', 'web', 'index.html'));
});
+ const desiredPort =
+ options?.previewServerPort ?? Internals.getPreviewServerPort();
+
const port = await getPort({
- port:
- options?.previewServerPort ||
- Internals.getPreviewServerPort() ||
- getPort.makeRange(3000, 3100),
+ port: desiredPort ?? getPort.makeRange(3000, 3100),
});
+
+ // If did specify a port but did not get that one, fail hard.
+ if (desiredPort && desiredPort !== port) {
+ throw new Error(
+ `You specified port ${desiredPort} to be used for the preview server, but it is not available. Choose a different port or remove the setting to let Remotion automatically select a free port.`
+ );
+ }
+
app.listen(port);
return port;
};