我刚刚用 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/