--open false as a cli arg does not prevent browser from opening
See original GitHub issue⚠️ IMPORTANT ⚠️ Please do not ignore this template. If you do, your issue will be closed immediately.
- Read the docs.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- This is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
Describe the bug
We are trying to use the cli argument --open false
to prevent the browser from opening when starting up a server but it does not work. If we do add the config option in vite.config.ts
it does work.
I tracked down the reason and this is due to a type mismatch when deciding whether to open the browser. Because the cli arg will always come through as a string ‘false’ will evaluate to truth in the block below.
if (options.open && !isRestart) {
const path = typeof options.open === 'string' ? options.open : base;
openBrowser(`${protocol}://${hostname}:${port}${path}`, true, server.config.logger);
}
My teammate and I did notice that depending on OS and browser default, the call in openBrowser
will fail silently as well.
Reproduction
Any project that tries to use --open false as a cli arg.
System Info
vite
version: 2.0.5- Operating System: OSx 10.15.7
- Node version: v14.14.0
- Package manager (npm/yarn/pnpm) and version: yarn v1.22.10
I am happy to open an MR if there is a specific direction to get this to work correctly. My first thought was just to check against ‘false’ if typeof options.open is a string and not even call openBrowser if that condition is met.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top GitHub Comments
@matias-capeletto -
--no-open
is perfect for our use case, we weren’t aware it was an option.When we ran the
vite --help
command, we didn’t see--no-open
but this works perfectly.What are your thoughts on an MR to update the docs and/or change the
--help
output to show--no-open
as an option and remove boolean as a type to--open
@drobannx Would love to see (and review) a docu update Could you create a PR for that? I think you don’t need to create an extra issue for that, we will jump directly into the PR 🙂
I will close this issue for now 👍