The error message tells that the variable sheet
does not refer to a sheet (tab) in the spreadsheet but to the whole spreadsheet.
The .getRange('A1')
method exists with both sheet and spreadsheet objects. With a spreadsheet object, the method gets a range in the sheet that shows as the first one in the tab bar of the spreadsheet. The .getRange(1, 1)
method, however, is only available with sheet objects.
To get a sheet object, use SpreadsheetApp.getActiveSheet() or similar methods, like this:
const sheet = SpreadsheetApp.getActiveSheet();