Export not always work?

I tried to export the selected Layer. Sometimes it does work, but sometimes it doesn’t. The result of the batchPlay is just an empty {}

 "requiredPermissions": {
        "localFileSystem": "fullAccess"
 },
let layerID =  app.activeDocument.layers[0].id //Assume the first layer to export

let tempFolder = await fs.getTemporaryFolder();
      console.log(tempFolder.nativePath);
      const selectCommand = {
        _obj: "select",
        _target: [
          {
            _ref: "layer",
            _id: layerID,
          },
        ],
        makeVisible: false,
        layerID: [layerID],
        _isCommand: false,
      };

      const exportCommand = {
        _obj: "exportSelectionAsFileTypePressed",
        _target: { _ref: "layer", _enum: "ordinal", _value: "targetEnum" },
        fileType: "png",
        quality: 32,
        metadata: 0,
        destFolder: tempFolder.nativePath, //destFolder.nativePath,
        sRGB: true,
        openWindow: false,
        _options: { dialogOptions: "dontDisplay" },
      };
      
      await core.executeAsModal(
        async () => {
          await action.batchPlay([selectCommand, exportCommand], {
            modalBehavior: "execute",
            synchronousExecution: false,
          });
        },
        { commandName: `Export Layer As PNG` }
      );

Can someone just quick test if this works?

I also tried this

await PS.core.executeAsModal(async () => {
  const folder = await fs.getEntryWithUrl(
    "D:\\UnityProject\\illness hero\\Assets\\Sprites"
  );
  
  const token = await fs.createPersistentToken(folder);
  
  console.log(folder.nativePath);
  // const tempFolder = await fs.getTemporaryFolder();
  const file = await folder.createFile("test.png", {
    overwrite: true,
  });
  
  const currentDocument = PS.app.activeDocument;
  await currentDocument.saveAs.png(
    file,
    {
      compression: 9,
    },
    true
  );
  
  console.log("File created: ", file.nativePath);
  });