【问题标题】:Cordova browser error科尔多瓦浏览器错误
【发布时间】:2026-01-04 00:45:01
【问题描述】:

我想测试 cordova 并构建一个简单的测试应用。 我按照https://cordova.apache.org/#getstarted的步骤进行操作

以下是一些输出(之前的输出没有错误):

C:\Users\jnq\Desktop\testCordova\TestLights>cordova platform add browser
Adding browser project...
Running command: cmd "/s /c "C:\Users\jnq\.cordova\lib\npm_cache\cordova-browser\4.1.0\package\bin\create.bat
C:\Users\jnq\Desktop\testCordova\TestLights\platforms\browser     io.cordova.hellocordova HelloCordova""
Creating Browser project. Path: platforms\browser
Error loading cordova-browser
Installing "cordova-plugin-whitelist" for browser

C:\Users\jnq\Desktop\testCordova\TestLights>cordova run browser
Error loading cordova-browser
Running command: cmd "/s /c "C:\Users\jnq\Desktop\testCordova\TestLights\platforms\browser\cordova\build.bat""
Cleaning Browser project
Running command: cmd "/s /c "C:\Users\jnq\Desktop\testCordova\TestLights\platforms\browser\cordova\run.bat --nobuild""
Static file server running @ http://localhost:8000/index.html
CTRL + C to shut down

我最终打开了一个 chrome 浏览器,但出现错误:ERR_CONNECTION_RESET

我跳过了什么吗? 如何使用cordova的浏览器平台?

谢谢, JNQ。

编辑:这是带有详细选项的添加命令:

No scripts found for hook "before_platform_add".
No version supplied. Retrieving version from config.xml...
Adding browser project...
Failed to require PlatformApi instance for platform "browser". Using polyfill instead.
Running command: cmd "/s /c "C:\Users\jnq\.cordova\lib\npm_cache\cordova-browser\4.1.0\package\bin\create.bat C:\Users\jnq\Desktop\testCordova\TestLights\platforms\browser io.cordova.hellocordova HelloCordova""
Creating Browser project. Path: platforms\browser
Command finished with error code 0: cmd /s /c "C:\Users\jnq\.cordova\lib\npm_cache\cordova-browser\4.1.0\package\bin\create.bat C:\Users\jnq\Desktop\testCordova\TestLights\platforms\browser io.cordova.hellocordova HelloCordova"
Error loading cordova-browser
Checking for any plugins added to the project that have not been installed in browser platform
No differences found between plugins added to project and installed in browser platform. Continuing...
Generating config.xml from defaults for platform "browser"
Installing plugin "cordova-plugin-whitelist" following successful platform add of browser
Found variables for "cordova-plugin-whitelist". Processing as cli_variables.
Installing "cordova-plugin-whitelist" for browser
Running command: cmd "/s /c "C:\Users\jnq\Desktop\testCordova\TestLights\platforms\browser\cordova\version.bat""
Command finished with error code 0: cmd /s /c "C:\Users\jnq\Desktop\testCordova\TestLights\platforms\browser\cordova\version.bat"
Finding scripts for "before_plugin_install" hook from plugin cordova-plugin-whitelist on browser platform only.
No scripts found for hook "before_plugin_install".
Install start for "cordova-plugin-whitelist" on browser.
Beginning processing of action stack for browser project...
Action stack processing complete.
Install complete for cordova-plugin-whitelist on browser.
Finding scripts for "after_plugin_install" hook from plugin cordova-plugin-whitelist on browser platform only.
No scripts found for hook "after_plugin_install".
No scripts found for hook "before_prepare".
Checking config.xml for saved platforms that haven't been added to the project
Checking for any plugins added to the project that have not been installed in browser platform
No differences found between plugins added to project and installed in browser platform. Continuing...
Generating config.xml from defaults for platform "browser"
No scripts found for hook "after_prepare".
Checking config.xml for saved plugins that haven't been added to the project
Saving browser@4.1.0 into platforms.json
No scripts found for hook "after_platform_add".

还有一个运行命令:

C:\Users\jnq\Desktop\testCordova\TestLights>cordova run browser --verbose
No scripts found for hook "before_run".
No scripts found for hook "before_prepare".
Checking config.xml for saved platforms that haven't been added to the project
Error loading cordova-browser
Checking for any plugins added to the project that have not been installed in browser platform
No differences found between plugins added to project and installed in browser platform. Continuing...
Generating config.xml from defaults for platform "browser"
No scripts found for hook "after_prepare".
Checking config.xml for saved plugins that haven't been added to the project
Running command: cmd "/s /c "C:\Users\jnq\Desktop\testCordova\TestLights\platforms\browser\cordova\build.bat""
Cleaning Browser project
Command finished with error code 0: cmd /s /c "C:\Users\jnq\Desktop\testCordova\TestLights\platforms\browser\cordova\build.bat"
No scripts found for hook "before_deploy".
Running command: cmd "/s /c "C:\Users\jnq\Desktop\testCordova\TestLights\platforms\browser\cordova\run.bat --nobuild""
Static file server running @ http://localhost:8000/index.html
CTRL + C to shut down

Edit2:显然我可以使用另一个端口然后 8000 运行它。

【问题讨论】:

  • 尝试使用cordova platform add browser --verbose查看添加进程的一些错误信息。
  • 我真的没有看到输出有任何问题:(
  • 所以这都是关于阻塞端口的吗?很好,祝你在学习 Cordova 时好运 :) 也试试 Ionic。
  • Ionic 似乎也很有趣,感谢您的帮助 :)
  • 如果你有 Visual Studio,你可以使用visualstudio.com/vs/cordova。我发现它比命令行的东西更容易。

标签: cordova


【解决方案1】:

如果您在使用带有 cordova 的浏览器平台时收到有关连接的错误,请尝试使用另一个端口: 科尔多瓦运行浏览器---port=8080

【讨论】: