2017-07-14 89 views
2

通過設置代理服務器,在公司防火牆後面有任何與create-react-app一起工作的方法。在公司防火牆後面使用create-react-app

我已經設置好的上NPM和紗線的代理,但是這是我所看到的,當嘗試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. 

回答

2

作爲一種變通方法,嘗試先在一個空文件夾中運行yarn add react react-dom react-scripts。這會將所需的包添加到紗線的本地緩存中。然後,您可以刪除該文件夾,然後再次運行create-react-app my-app,並且希望能夠正常工作。

1

此問題是由一個事實,即紗線註冊表是由於硬編碼在反應-腳本registry.yarnpkg.comhttps://github.com/facebookincubator/create-react-app/blob/master/packages/create-react-app/createReactApp.js#L692

this pull request,如果紗線註冊表不可達,然後it will check看到,如果你有https_proxy環境變量集,然後如果是這樣,它將驗證服務器是否可達,而不是硬編碼的紗線註冊表。

重申一下,在npm/yarn中設置proxy/https-proxy配置是不夠的 - 您還需要設置https_proxy環境變量,因爲這是create-react-app在確定您是否在線時會檢查。例如:

https_proxy=https://my.corporate.proxy create-react-app my-new-project 
相關問題