create-react-app通过设置代理,可以在公司防火墙后面使用任何方法。
create-react-app
我已经在npm和yarn上设置了代理,但这是我在尝试执行create-react-app my-app以下操作时看到的内容:
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.
更新: 看来此错误已得到修复,在版本1.1.0中不再存在。
此问题是由以下事实造成的:毛线注册表在react- scripts中硬编码为registry.yarnpkg.com:https : //github.com/facebookincubator/create-react-app/blob/master/packages/create- react-app/createReactApp .js#L692
registry.yarnpkg.com
根据此拉取请求,如果无法访问yarn注册表,则它将检查是否https_proxy设置了环境变量,如果是,则它将验证 该 服务器是否可访问,而不是硬编码的yarn注册表。
https_proxy
重申一下,在npm / yarn中设置proxy / https-proxy配置是不够的- 您还需要设置https_proxy环境变量,因为这是create-react-app在确定您是否在线时将检查的内容。例如:
https_proxy=https://my.corporate.proxy create-react-app my-new-project