【问题标题】:Use create-react-app behind corporate firewall在企业防火墙后面使用 create-react-app
【发布时间】:2019-02-07 19:29:04
【问题描述】:

有任何方法可以通过设置代理在公司防火墙后面使用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.

【问题讨论】:

  • 致未来的读者:create-react-app 的最新版本在检测代理等方面变得更加智能。请确保您运行的是最新版本,然后重试!

标签: node.js reactjs


【解决方案1】:

这些设置为我解决了这个问题:

npm config set proxy http://username:password@host:port
npm config set https-proxy http://username:password@host:port

【讨论】:

    【解决方案2】:

    这解决了我的问题 - See details npm config set registry "https://registry.npmjs.org"

    【讨论】:

      【解决方案3】:

      我也遇到过这个问题,我用这个命令解决了这个问题:

      create-react-app hello-world --use-npm --cache /tmp/empty-cache
      

      【讨论】:

        【解决方案4】:

        我已经为此苦苦挣扎了好几个星期。对我有用的是在命令末尾包含 --use-npm ,最后我摆脱了“找不到锁文件”错误。我真诚地希望这可以帮助其他遇到同样问题的人。

        【讨论】:

        • 嗨,Erik,--use-npm 完美运行,感谢分享您的解决方案!
        • 谢谢埃里克!
        • --use-npm 也为我工作,strict-ssl=falsealways-auth=true_authca
        • 完美,谢谢。我的公司代理有点烦人,所以这个修复很简单有效。
        【解决方案5】:

        更新:看起来这个错误有now been fixed,应该不再出现在version 1.1.0中。


        这个问题是由于 yarn 注册表在 react-scripts 中被硬编码为registry.yarnpkg.com:https://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
        

        【讨论】:

          【解决方案6】:

          作为一种解决方法,请先尝试在空文件夹中运行yarn add react react-dom react-scripts。这会将所需的包添加到 yarn 的本地缓存中。然后,您可以删除该文件夹并再次运行 create-react-app my-app,希望它会起作用。

          【讨论】:

            猜你喜欢
            • 2010-09-16
            • 2016-02-11
            • 1970-01-01
            • 2020-10-24
            • 2017-11-29
            • 2015-09-17
            • 1970-01-01
            • 2013-12-10
            相关资源
            最近更新 更多