npm命令create-react-app失败

时间:2017-09-01 08:43:25

标签: macos reactjs npm npm-install create-react-app

我正在尝试在运行OsX sierra 10.12.6的计算机上测试reactjs(mbp pro 2017)。 我已经关注了Facebook教程:

  1. 确保安装了最新版本的Node.js. (完成)
  2. 按照安装说明创建新项目https://facebook.github.io/react/docs/installation.html#creating-a-new-application
  3. 但是我在第二步遇到了问题!

    • 我不是代理人。
    • 我的网络还可以。
    • 存储库设置为registry.npmjs.org
    • 我可以阅读网址:https://registry.npmjs.org/create-react-app
    • 但即使在外部DNS上也找不到此域 wsg.intra.corp.grp

    我被困了,任何帮助都会很好!

    $ npm install -g create-react-app
    npm ERR! code ENOTFOUND
    npm ERR! errno ENOTFOUND
    npm ERR! network request to https://registry.npmjs.org/create-react-app failed, reason: getaddrinfo ENOTFOUND wsg.intra.corp.grp wsg.intra.corp.grp:8080
    npm ERR! network This is a problem related to network connectivity.
    npm ERR! network In most cases you are behind a proxy or have bad network settings.
    npm ERR! network 
    npm ERR! network If you are behind a proxy, please make sure that the
    npm ERR! network 'proxy' config is set properly.  See: 'npm help config'
    
    npm ERR! A complete log of this run can be found in:
    npm ERR!     ~/.npm/_logs/2017-09-01T08_15_13_521Z-debug.log
    

    日志文件:

    0 info it worked if it ends with ok
    1 verbose cli [ '/usr/local/bin/node',
    1 verbose cli   '/usr/local/bin/npm',
    1 verbose cli   'install',
    1 verbose cli   '-g',
    1 verbose cli   'create-react-app' ]
    2 info using npm@5.3.0
    3 info using node@v8.4.0
    4 verbose npm-session 4811d091ad74f9ef
    5 silly install loadCurrentTree
    6 silly install readGlobalPackageData
    7 silly fetchPackageMetaData error for create-react-app@latest request to https://registry.npmjs.org/create-react-app failed, reason: getaddrinfo ENOTFOUND wsg.intra.corp.grp wsg.intra.corp.grp:8080
    8 verbose type system
    9 verbose stack FetchError: request to https://registry.npmjs.org/create-react-app failed, reason: getaddrinfo ENOTFOUND wsg.intra.corp.grp wsg.intra.corp.grp:8080
    9 verbose stack     at ClientRequest.req.on.err (/usr/local/lib/node_modules/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/node-fetch-npm/src/index.js:68:14)
    9 verbose stack     at emitOne (events.js:115:13)
    9 verbose stack     at ClientRequest.emit (events.js:210:7)
    9 verbose stack     at onerror (/usr/local/lib/node_modules/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/https-proxy-agent/node_modules/agent-base/index.js:106:9)
    9 verbose stack     at callbackError (/usr/local/lib/node_modules/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/https-proxy-agent/node_modules/agent-base/index.js:126:5)
    9 verbose stack     at <anonymous>
    9 verbose stack     at process._tickCallback (internal/process/next_tick.js:188:7)
    10 verbose cwd /Users/franckfournier/PycharmProjects/projectX/react
    11 verbose Darwin 16.7.0
    12 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "create-react-app"
    13 verbose node v8.4.0
    14 verbose npm  v5.3.0
    15 error code ENOTFOUND
    16 error errno ENOTFOUND
    17 error network request to https://registry.npmjs.org/create-react-app failed, reason: getaddrinfo ENOTFOUND wsg.intra.corp.grp wsg.intra.corp.grp:8080
    18 error network This is a problem related to network connectivity.
    18 error network In most cases you are behind a proxy or have bad network settings.
    18 error network
    18 error network If you are behind a proxy, please make sure that the
    18 error network 'proxy' config is set properly.  See: 'npm help config'
    19 verbose exit [ 1, true ]
    

5 个答案:

答案 0 :(得分:3)

您似乎支持公司代理,因为日志中提到了wsg.intra.corp.grp:8080

您需要像previous question中所示配置代理。

希望这有帮助!

答案 1 :(得分:0)

在Github上跟随this post,并在/ etc / hosts中添加“ 104.18.95.96 Registry.npmjs.org”解决了我的问题。

答案 2 :(得分:0)

如果您仍然遇到问题,请执行以下步骤:

  1. 转到“设置”>“网络和Internet”>“代理”,然后找到地址和端口
  2. 根据您的计算机转到命令提示符或终端(提示:按下Win + R,然后键入cmd)。在命令提示符下,键入以下命令

npm配置集代理http://usernamepassword@proxy-server-url:port

npm配置设置为https-proxy http://usernamepassword@proxy-server-url:port

实际上不需要用户名和密码(十分之九),最后2个就足够了。 Proxy-server-url是您的地址,端口是端口号。设置完成后,关闭命令提示符,然后重新打开。瞧!您现在可以安装所有软件包

来源 https://medium.com/@ogbemudiatimothy/using-npm-install-behind-a-corporate-proxy-server-db150c128899

答案 3 :(得分:0)

我刚刚解决了这个问题, 转到设置>网络和Internet>代理,然后在Windows上的自动代理设置下关闭自动检测设置。然后安装正常。

答案 4 :(得分:0)

在命令提示符下运行以下命令。确保安装了 node 和 npm。

npm config rm proxy

npm config rm https-proxy

在浏览器中打开此链接:https://registry.npmjs.org/

运行下面的命令来设置注册表。

npm config set registry https://registry.npmjs.org/

希望对您有所帮助:)