_setupRole from AccessControl.sol is showing compile-time errors using hardhat/foundry whereas works fine with Remix-IDE

I am trying to call a simple function from AccessControl.sol file of openzeppelin and the line of code is as below:

_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());

Now, when I compile the SC using hardhat or foundry in my VS code, I am reverted with an error that the function is not declared anywhere. Whereas, there no such error thrown on Remix IDE. It compiles just fine on Remix.

Can anyone help me understand how to resolve this issue

You're probably using OZ v4 on Remix IDE, but OZ v5 on your HardHat project configuration.

On v5, _setupRole has been deprecated in favor of _grantRole, which performs the same operation.