When importing both @openzeppelin/contracts and @openzeppelin/contracts-upgradeable, the Solidity compiler throws:
DeclarationError: Identifier already declared.
This happens because both versions define a contract named Initializable.
Steps to Reproduce:
- Install both packages:
npm install @openzeppelin/contracts @openzeppelin/contracts-upgradeable
- Import both in a single contract:
import "@openzeppelin/contracts/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
- Compile using Hardhat or Foundry.
Expected Behavior:
Either a clearer compiler error or a unified import strategy in docs to avoid confusion.
💻 Environment
- Solidity: 0.8.26
- Hardhat: 2.22.x
- OpenZeppelin Contracts: 5.x
- OpenZeppelin Contracts Upgradeable: 5.x