41

When I try to run my migration with truffle migrate the following error message appears:

Error: No network specified. Cannot determine current network.
    at Object.detect (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:43157:23)
    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:200497:19
    at finished (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:43085:9)
    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:198408:14
    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:68162:7
    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:163793:9
    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:160353:16
    at replenish (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:160873:25)
    at iterateeCallback (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:160863:17)
    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:160838:16

This is on an OSX machine and I am using truffle version 4.0.0, solidity version 0.4.18. TestRPC v4.1.3 is running in the background.

65

Make sure that you have configured your network in truffle.js. It should look something like this for the setup mentioned above:

module.exports = {
    networks: {
        development: {
            host: "localhost",
            port: 8545,
            network_id: "*" // Match any network id
        }
    }
};
13

I had the same problem with truffle 4.0.1. After some investigation and advise from the truffle team I figured out that truffle 4.0.x has a new option. If you run truffle develop you don't need testrpc anymore. Since truffle develop runs on port 9545 you have to modify your truffle.js to something like this

networks: {
    development: {
          host: "localhost",
          port: 9545,
          network_id: "*" // Match any network id
    }
}

truffle 4.0.x has some other cool new features. I recommend to checkout the release notes of truffle 4.0.0. They can be found here https://github.com/trufflesuite/truffle/releases/tag/v4.0.0 They also recommend to upgrade to truffle 4.0.1.

I hope that helps

  • 1
    thanks @Bumblebee, I was facing similar error. Now it works perfectly. – Geeky Ninja Aug 17 '18 at 11:23
1

or you can specify network:

your truffle.js:

module.exports = {
  networks: {
    privateNode: {
      host: '127.0.0.1',
      port: 8501,               
      network_id: '*'
    },
    ganache: {
      host: "127.0.0.1",
      port: 7545,
      network_id: "*"
    }
  }
};

console command line:

truffle migrate --network ganache  //this can open only truffle.js and does not run the script

truffle.cmd migrate --network ganache //this would run script for 100%
1

Please check truffle config file. Mine got resolved by following code, Comment out Ganache network and replace with Development to test

module.exports = {
networks: {
  /*  ganache: {
        host: "localhost",
        port: 7545,
        gas: 5000000,
        network_id: "*" // Match any network id
    }*/

    // Make sure it should connecto to development environment
    development: {
        host: "localhost",
        port: 7545,
        gas: 5000000,
        network_id: "*" // Match any network id
    }
}

};

1

I was also getting similar error, when I was referring to a website which was not using network_id (May be due to configuration update as I was using the latest truffle version).

This worked for me! Edit your truffle.js or truffle-config.js file as below:

module.exports = {  
 networks: {
  development: {
  host: "localhost",
  port: 8545,
  network_id: "*"
 }
}
}

Note: Above example is for development network that matches any network it connects to (that is why network_id: "*" is being used). If the user wants to configure Truffle to connect to any other network or networks, you just need to add more named networks and specify the corresponding network id.

  • Would you mind to describe what makes your answer more useful than the already given answers, I fail to see the difference? – bummi May 14 at 12:11
0

You might run in this error if you're running truffle migrate in using the old configuration file, which was something like this:

module.exports = {
    build: {
      "index.html": "index.html",
      "app.js": [
        "javascripts/app.js"
      ],
      "app.css": [
        "stylesheets/app.css"
      ],
      "images/": "images/"

    },
    rpc: {
      host: "localhost",
      port: 8545
    }
};

At this time you need to use this config:

module.exports = {
  networks: {
     development: {
     host: "localhost",
     port: 8545,
     network_id: "*" // Match any network id
   }
 }
};

You also multiple environments developement or live, use network_id to specify the blockchain network (mainnet, or Ropsten...), more details:

http://truffleframework.com/docs/advanced/configuration

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.