Corepack 和 Yarn 问题 -yarn init -2 因请求错误而失败

问题描述 投票:0回答:1

问题

如何在 Windows 10 下修复此问题

  • 为纱线 v1.22.22 运行
    C:\>yarn exec env
    最初返回
    error Couldn't find the binary env
    ,现在返回
    error Couldn't find the binary env
  • 运行
    yarn install
    失败并显示
    Request Error: at ClientRequest.<anonymous> 

我尝试过的事情

纱线安装说明指出要运行

corepack enable

C:\>corepack enable
C:\>corepack -v
0.23.0

这似乎有效。下一步是运行

yarn init -2
但这已经失败了

C:\dev\yarn_test>yarn init -2
Internal Error: ENOENT: no such file or directory, 
                stat '%userprofile%\AppData\Local\node\corepack\yarn\4.2.1'
Error: ENOENT: no such file or directory, 
               stat '%userprofile%\AppData\Local\node\corepack\yarn\4.2.1'
error Command failed.
Exit code: 1
Command: C:\Program Files\nodejs\node.exe
Arguments: C:\Program Files\nodejs\node_modules\corepack\dist\corepack.js 
              yarn@stable init -2 --install=self
Directory: C:\dev\yarn_test
Output:

info Visit https://yarnpkg.com/en/docs/cli/init for documentation about this command.

运行

dir %userprofile%\AppData\Local\node\corepack\yarn\
显示没有4.*目录。

页面yarnpkg.com/corepack推荐

可以快速查看Corepack是否启用 通过运行

yarn exec env
:如果你得到一个路径作为输出, Corepack 已正确安装。如果没有,可能会出现问题 以及垫片的安装方式。在这种情况下,请检查故障排除 建议部分。

运行

yarn exec env
失败,并显示

C:\>yarn exec env
yarn exec v1.22.22
error Couldn't find the binary env
info Visit https://yarnpkg.com/en/docs/cli/exec for documentation about this command.

使用 npm 安装 corepack

下一个建议是以管理员身份运行后运行

npm install -g corepack
版本已升级到
corepack -v   0.28.0

现在再次运行

yarn init -2
似乎可以工作

! Corepack is about to download https://repo.yarnpkg.com/4.1.1/packages/yarnpkg-cli/bin/yarn.js
? Do you want to continue? [Y/n] Y`
...

但它因请求错误而失败

Request Error:
    at ClientRequest.<anonymous> 
       (%userprofile%\AppData\Local\node\corepack\v1\yarn\4.1.1\yarn.js:147:14258)
    at Object.onceWrapper (node:events:633:26)
    at ClientRequest.emit (node:events:530:35)
    at u.emit 
       (%userprofile%\AppData\Local\node\corepack\v1\yarn\4.1.1\yarn.js:142:14420)
    at TLSSocket.socketErrorListener (node:_http_client:495:9)
    at TLSSocket.emit (node:events:518:28)
    at emitErrorNT (node:internal/streams/destroy:169:8)
    at emitErrorCloseNT (node:internal/streams/destroy:128:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)AggregateError
    at internalConnectMultiple (node:net:1114:18)
    at afterConnectMultiple (node:net:1667:5)

运行

yarn check
似乎工作正常 - 它返回:

yarn check v1.22.22
success Folder in sync.
Done in 0.09s.

克隆示例并尝试安装它

我的盒子使用公司反向代理。连接到互联网需要像这样的用户名和密码

http://<user>:<pass>@<our-proxy>.foo.bar:port
并存储在环境变量
echo %HTTP_PROXY%
中。但这已经为 npm 设置了(尽管我的电脑也有 npm 问题

成功克隆此示例项目后

git clone https://github.com/salesforce/utam-js-recipes.git
运行
C:\dev\utam\utam-js-recipes>yarn install
再次失败并显示

C:\dev\utam\utam-js-recipes>yarn install
! Corepack is about to download https://repo.yarnpkg.com/4.0.2/packages/yarnpkg-cli/bin/yarn.js
? Do you want to continue? [Y/n] Y
➤ YN0000: ⠼ ====----------------------------------------------------------------------------
➤ YN0000: · Yarn 4.0.2
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: ⠴ ====----------------------------------------------------------------------------
    at ClientRequest.<anonymous> 
(%userprofile%\AppData\Local\node\corepack\v1\yarn\4.0.2\yarn.js:147:14258)
    at Object.onceWrapper (node:events:633:26)
    at ClientRequest.emit (node:events:530:35)
    at u.emit 
(%userprofile%\AppData\Local\node\corepack\v1\yarn\4.0.2\yarn.js:142:14420)
    at TLSSocket.socketErrorListener (node:_http_client:495:9)
    at TLSSocket.emit (node:events:518:28)
    at emitErrorNT (node:internal/streams/destroy:169:8)
    at emitErrorCloseNT (node:internal/streams/destroy:128:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)AggregateError
    at internalConnectMultiple (node:net:1114:18)
    at afterConnectMultiple (node:net:1667:5)
➤ YN0001: │ RequestError
    at ClientRequest.<anonymous> 
(%userprofile%\AppData\Local\node\corepack\v1\yarn\4.0.2\yarn.js:147:14258)

将代理添加到配置中

我不确定是否需要此步骤,因为我已经有代理的环境变量,但我确实运行了

yarn config set httpProxy http://<user>:<pass>@<our-proxy>.foo.bar:PORT
yarn config set strict-ssl false
node.js corepack yarnpkg-v4
1个回答
0
投票

是的,需要添加 Yarn 4.x 的代理设置(httpProxyhttpsProxy)。

yarn config set httpProxy http://<user>:<pass>@<your-proxy>.foo.bar:PORT
yarn config set httpsProxy http://<user>:<pass>@<your-proxy>.foo.bar:PORT
© www.soinside.com 2019 - 2024. All rights reserved.