Put a layer group inside another layer group

What is the correct way to put a layer group inside another layer group?

I’ve tried both

await subGroup.moveInside(mainGroup);


await subGroup.move(mainGroup, constants.ElementPlacement.PLACEINSIDE);

They both throw this error:

  TypeError: Cannot read property 'id' of undefined
      at _directRef (uxp://uxp-internal:1)
      at Layer.moveInside (uxp://uxp-internal:1)
      at Layer.move (uxp://uxp-internal:1)
      at createGroups (VM14 index.js:238)
      at async _internalExecuteAsModalWrapper (C:\Program Files\Adobe\Adobe Photoshop 2022\Required\UXP/common.js:54)
      at async _internalCallbackWrapper (C:\Program Files\Adobe\Adobe Photoshop 2022\Required\UXP/common.js:35)

This is using API v2 and the code is being run inside a modal scope

Here is the full code:

async function createGroups(executionContext, descriptor)
	try {
		let mainGroup = await app.activeDocument.createLayerGroup({ name: "main group" });
		let subGroup = await app.activeDocument.createLayerGroup({ name: "sub group" });
		await subGroup.move(mainGroup, require('photoshop').constants.ElementPlacement.PLACEINSIDE);
	catch (err) {
async function RunClicked()
	await require('photoshop').core.executeAsModal(createGroups, {"commandName": "Creating nested groups"});

I get the same problem when trying to move a normal layer inside a group layer. The only solution I can see at this stage is to move back to API v1 where .moveBelow() acts as moveInside().