reactjs - 为什么 vscode 在边缘而不是 chrome 中打开 React 应用程序?

标签 reactjs typescript visual-studio-code

我刚刚用 react-create-app 模板 typescript 开始了一个项目。

当我执行 npm run dev 时,它会打开 edge 浏览器,我期待的是 chrome。

知道如何在 chrome 中打开它吗?

最佳答案

From Create React App documentation

By default, Create React App will open the default system browser, favoring Chrome on macOS. Specify a browser to override this behavior, or set it to none to disable it completely. If you need to customize the way the browser is launched, you can specify a node script instead. Any arguments passed to npm start will also be passed to this script, and the url where your app is served will be the last argument. Your script's file name must have the .js extension.

简单的答案是更改您的默认浏览器。但是,如果您想将默认浏览器保留为 Edge,您可以这样做。

BROWSER=chrome npm start
BROWSER=chrome npm run dev

请考虑浏览器名称不同。例如,Chrome 在 macOS 上是 google chrome,在 Linux 上是 google-chrome,在 Windows 上是 chrome。

Linux
"start": "BROWSER='google-chrome-stable' react-scripts start"
Windows
"start": "BROWSER='chrome' react-scripts start"
Mac
"start": "BROWSER='google chrome' react-scripts start"

关于reactjs - 为什么 vscode 在边缘而不是 chrome 中打开 React 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66212423/

相关文章:

node.js - 使用自定义 Node 脚本作为 shell 创建 Visual Studio Code 集成终端

visual-studio-code - 使用 Visual Studio Code 的多个命令/任务

reactjs - MUI 组件与 React Bootstrap

typescript - 静态注入(inject)错误或 Please add a @NgModule annotation error from angular

javascript - 如何选择 node_modules dist flavor 与 webpack 捆绑在一起

python - VS 代码和 Python 中自动化对象的自动完成

reactjs - Jest : SVG require causes "SyntaxError: Unexpected token <"

javascript - 使用 onclick 渲染对象数组中的数据

javascript - Reactjs 中的样式化组件

node.js - 如何在 NodeJS 中使用只有 URL 的 Sharp 调整图像大小,使用 async/await,并且没有创建本地副本?