Upgradable contract error with Hardhat: "Deployment at address is not registered"

Hello community.
There is an answer to this problem using truffle. But it is not clear to me how to solve the problem with hardhat.

Develop destroyed the JSON of the contents of the .openzeppelin folder where the manifestVersion, the admin contract, the proxies contracts and the implementations registry are located.

We deduce that if we manipulate somehow that JSON of a older version we could get it to work.
Is such a thing possible?

In the answer linked in truffle it is commented that it can be solved manually.
We see that we can deploy from Remix without being very clear if it is really updating those contracts.

Then, there is the solution suggested by hardhat:

To register a previously deployed proxy for upgrading, use the forceImport function.
We do not understand very well where this function has to be placed to perform this forced import and if it must be removed later.

forceImport

From the structure of the code I understand that it will have to be added in some hardhat script, right?

async function forceImport(
  address: string,
  deployedImpl: ethers.ContractFactory,
  opts?: {
    kind?: 'uups' | 'transparent' | 'beacon',
  },
): Promise<ethers.Contract>

If there is any example to check how to perform this process I would appreciate it. In any case clarify the process to be able to force the import and continue working from hardhat.

Or even if there is an alternative way to solve this problem.

Hi, the forceImport function is indeed what you should use. It can be called from a separate Hardhat script, which does nothing other than calling forceImport for each of the proxies that you have previously deployed. Ensure that you pass an ethers contract factory corresponding to the current implementation contract that is being used by each proxy.

Importing proxies would also import their implementation addresses automatically. For older versions of Hardhat Upgrades, it would also import the admin contract automatically if needed (note the admin field is no longer used as of Hardhat Upgrades v3.0.0 or later).

After you have finished importing, you no longer need the script that calls forceImport -- it can be deleted.