'Network ropsten doesn't exist

I get this error everytime I try to launch the contract with npx hardhat --network ropsten run scripts/deployPizzaHeadNFT.js

require("@nomiclabs/hardhat-waffle");
        const dotenv = require("dotenv");
        dotenv.config();
        // This is a sample Hardhat task. To learn how to create your own go to
        // https://hardhat.org/guides/create-task.html
        task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
          const accounts = await hre.ethers.getSigners();
        
          for (const account of accounts) {
            console.log(account.address);
          }
        });
        
        // You need to export an object to set up your config
        // Go to https://hardhat.org/config/ to learn more
        
        /**
         * @type import('hardhat/config').HardhatUserConfig
         */
        module.exports = {
          solidity: "0.8.4",
          networks: {
            rinkeby: {
              url: process.env.REACT_APP_RINKEBY_RPC_URL
              accounts: [process.env.REACT_APP_PRIVATE_KEY],
            },
          },
          etherscan: {
            apiKey: process.env.REACT_APP_ETHERSCAN_KEY,
          },
        };


Solution 1:[1]

module.exports = {
      solidity: "0.8.4",
      networks: {
        rinkeby: {
          url: process.env.REACT_APP_RINKEBY_RPC_URL
          accounts: [process.env.REACT_APP_PRIVATE_KEY],
        },
      },
      etherscan: {
        apiKey: process.env.REACT_APP_ETHERSCAN_KEY,
      },
    };

As you can see you didn't add the Ropsten network inside the networks object, so that's the reason. Your config will be something like this:

networks {
  rinkeby: {
    url: process.env.REACT_APP_RINKEBY_RPC_URL
    accounts: [process.env.REACT_APP_PRIVATE_KEY],
  },
  ropsten: {
    url: process.env.REACT_APP_ROPSTEN_RPC_URL
    accounts: [process.env.REACT_APP_PRIVATE_KEY],
  },
  ... You can add as many networks as you want
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Niccolò Fant