diff --git a/.changeset/beige-trees-confess.md b/.changeset/beige-trees-confess.md new file mode 100644 index 000000000000..892f9fbf37f3 --- /dev/null +++ b/.changeset/beige-trees-confess.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +[feat] allow using Vite's `strict.port: false` option diff --git a/packages/kit/src/cli.js b/packages/kit/src/cli.js index 34a081932172..f4c33c4308ef 100644 --- a/packages/kit/src/cli.js +++ b/packages/kit/src/cli.js @@ -84,8 +84,6 @@ prog .option('-H, --https', 'Use self-signed HTTPS certificate', false) .option('-o, --open', 'Open a browser tab', false) .action(async ({ port, host, https, open }) => { - await check_port(port); - process.env.NODE_ENV = process.env.NODE_ENV || 'development'; const config = await get_config(); @@ -102,7 +100,15 @@ prog process.stderr.write(data); }); - welcome({ port, host, https, open }); + if (!watcher.vite || !watcher.vite.httpServer) { + throw Error('Could not find server'); + } + // we never start the server on a socket path, so address will be of type AddressInfo + const chosen_port = /** @type {import('net').AddressInfo} */ ( + watcher.vite.httpServer.address() + ).port; + + welcome({ port: chosen_port, host, https, open }); } catch (error) { handle_error(error); } diff --git a/packages/kit/src/core/dev/index.js b/packages/kit/src/core/dev/index.js index 42477b0bcccf..585af735de23 100644 --- a/packages/kit/src/core/dev/index.js +++ b/packages/kit/src/core/dev/index.js @@ -102,7 +102,8 @@ class Watcher extends EventEmitter { server: { fs: { strict: true - } + }, + strictPort: true } };