gpt4 book ai didi

parceljs - 包裹: configured port 1234 could not be used

转载 作者:行者123 更新时间:2023-12-02 02:42:45 36 4
gpt4 key购买 nike

我需要在端口 1234 上运行我的 ReactJS 应用程序但是当我运行 yarn dev ,我得到以下信息:

$ parcel src/index.html --port 1234

Server running at http://localhost:2493 - configured port 1234 could not be used.

√ Built in 11.45s.



它没有告诉我 为什么它无法在端口 1234 上运行,所以我怀疑该端口可能已经在使用中。根据 this answer ,下面应该告诉我哪个进程正在使用该端口。
Get-Process -Id (Get-NetTCPConnection -LocalPort portNumber).OwningProcess

但这并没有帮助,它给出了以下信息:

Get-NetTCPConnection : No MSFT_NetTCPConnection objects found with property 'LocalPort' equal to '1234'. Verify the value of the property and retry.



我猜这意味着没有进程绑定(bind)到端口 1234 .但如果是这样的话,为什么我不能绑定(bind)到那个端口呢?

我的 package.json如下:
{
"name": "bejebeje.react",
"version": "1.0.0",
"description": "bejebeje's react-js frontend",
"main": "index.js",
"repository": "git@github.com:JwanKhalaf/Bejebeje.React.git",
"author": "John",
"license": "GPL-3.0",
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.19",
"@fortawesome/free-brands-svg-icons": "^5.9.0",
"@fortawesome/free-solid-svg-icons": "^5.9.0",
"@fortawesome/pro-light-svg-icons": "^5.9.0",
"@fortawesome/pro-regular-svg-icons": "^5.9.0",
"@fortawesome/pro-solid-svg-icons": "^5.9.0",
"@fortawesome/react-fontawesome": "^0.1.4",
"@reach/router": "^1.2.1",
"oidc-client": "^1.8.2",
"react": ">=16",
"react-dom": "^0.14.9 || ^15.3.0 || ^16.0.0-rc || ^16.0",
"react-icons": "^3.7.0",
"styled-components": "^4.3.2"
},
"scripts": {
"dev": "parcel src/index.html --port 1234",
"build": "parcel build src/index.html"
},
"devDependencies": {
"@fortawesome/fontawesome-pro": "^5.9.0",
"axios": "^0.19.0",
"parcel-bundler": "^1.12.3",
"prettier": "^1.16.4",
"sass": "^1.22.5"
}
}

最佳答案

在创建一个尝试绑定(bind)到端口 1234 的小型 C# Web 服务器之后我仍然无法让它工作。它会尝试绑定(bind),但会抛出异常:

An attempt was made to access a socket in a way forbidden by its access permissions.



无论如何,经过大量的痛苦和研究,这里终于奏效了:

首先,禁用 hyper-v(这将重新启动您的 PC,因此请确保保存所有工作)。在 PowerShell(以管理员身份)中运行以下命令:
dism.exe /Online /Disable-Feature:Microsoft-Hyper-V

当您的 PC 重新启动时,您需要保留所需的端口,以便 hyper-v 不会将其保留回来,再次以管理员身份通过 PowerShell,运行以下命令:
netsh int ipv4 add excludedportrange protocol=tcp startport=50051 numberofports=1

现在终于以管理员身份再次通过 PowerShell 重新启用 hyper-V(PC 将重新启动):
dism.exe /Online /Enable-Feature:Microsoft-Hyper-V /All

当您的 PC 完成并备份后,您应该能够成功绑定(bind)到该端口。

关于parceljs - 包裹: configured port 1234 could not be used,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58159069/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com