0 votes
1 view
in Blockchain by (27.5k points)

I am new to smart contract programming, recently installed truffle using npm on Node(version: 6.10.3) When I run the command truffle init the first time, I received this error:

events.js:160

      throw er; // Unhandled 'error' event

      ^

Error: connect ETIMEDOUT 151.101.8.133:443

    at Object.exports._errnoException (util.js:1018:11)

    at exports._exceptionWithHostPort (util.js:1041:20)

    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)

The next time I run truffle init, I got this error:

events.js:160

      throw er; // Unhandled 'error' event

      ^

Error: read ECONNRESET

    at exports._errnoException (util.js:1018:11)

    at TLSWrap.onread (net.js:568:26)

Any idea on how to resolve this?

1 Answer

0 votes
by (67.1k points)

To solve this error you can modify the cli.bundled.js: and replace the https.request with the request below is the code for the same:-

diff --git a/build/cli.bundled.js b/build/cli.bundled.js

    index 01c69e3..aa2605c 100755

    --- a/build/cli.bundled.js

    +++ b/build/cli.bundled.js

    @@ -202412,12 +202412,8 @@ var Init = {

           // will fail spectacularly in a way we can't catch, so we have to do it ourselves.

           return new Promise(function(accept, reject) {

    -        var options = {

    -          method: 'HEAD',

    -          host: 'raw.githubusercontent.com',

    -          path: '/trufflesuite/' + expected_full_name + "/master/truffle.js"

    -        };

    -        req = https.request(options, function(r) {

    +        var request = require('request');

    +        request({ method: 'HEAD', uri: 'https://raw.githubusercontent.com/trufflesuite/'+expected_full_name+'/master/truffle.js'}, function (error, r, body) {

               if (r.statusCode == 404) {

                 return reject(new Error("Example '" + name + "' doesn't exist. If you believe this is an error, please contact Truffle support."));

               } else if (r.statusCode != 200) {

    @@ -202425,7 +202421,6 @@ var Init = {

               }

               accept();

             });

    -        req.end();

           });

         }).then(function() {

    @@ -212634,4 +212629,4 @@ module.exports = require("solc");

     module.exports = require("string_decoder");

     /***/ })

    -/******/ ]);

    \ No newline at end of file

    +/******/ ]);

There are some prerequisites to run the above code which are as follows:

  1. Install request via npm (npm install -g request)

  2. Proxy - setup environment as described here

...