小编典典

在公司防火墙后使用create-react-app

reactjs

create-react-app通过设置代理,可以在公司防火墙后面使用任何方法。

我已经在npm和yarn上设置了代理,但这是我在尝试执行create-react-app my-app以下操作时看到的内容:

Creating a new React app in F:\react\my-app.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...

You appear to be offline.
Falling back to the local Yarn cache.

yarn add v0.23.4
info No lockfile found.
[1/4] Resolving packages...
error Couldn't find any versions for "react" that matches "latest" in our cache. Possible versions: ""
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

Aborting installation.
  yarnpkg add --exact --offline react react-dom react-scripts has failed.

Deleting generated file... package.json
Deleting my-app / from F:\react
Done.

阅读 377

收藏
2020-07-22

共1个答案

小编典典

更新: 看来此错误已得到修复,在版本1.1.0中不再存在。


此问题是由以下事实造成的:毛线注册表在react-
scripts中硬编码为registry.yarnpkg.comhttps :
//github.com/facebookincubator/create-react-app/blob/master/packages/create-
react-app/createReactApp
.js#L692

根据此拉取请求,如果无法访问yarn注册表,则它将检查是否https_proxy设置了环境变量,如果是,则它将验证
服务器是否可访问,而不是硬编码的yarn注册表。

重申一下,在npm / yarn中设置proxy / https-proxy配置是不够的-
您还需要设置https_proxy环境变量,因为这是create-react-app在确定您是否在线时将检查的内容。例如:

https_proxy=https://my.corporate.proxy create-react-app my-new-project
2020-07-22