Guides / n8n × Google Sheets / Triggers & webhooks

Fix n8n Google Sheets "Cannot read properties of undefined (reading '!ref')" on Activation

What this specific internal error means when activating a Google Sheets trigger, and the sheet-reference conditions that cause it.

Flat vector diagram illustrating the fix n8n google sheets cannot read ref undefined activation error and fix.
Cannot read properties of undefined (reading '!ref')
Short answer: This is not a Google error. "!ref" is the key a spreadsheet-parsing library uses for a worksheet's used-range, and the message means the node asked for a worksheet object that came back undefined and then read a property off it. In practice the sheet (tab) named in the node no longer exists under that name, the spreadsheet is empty or has no grid data in the requested range, or the API returned a response the parser did not expect. Verify the tab name and range against the live spreadsheet before treating it as an n8n defect.

What this specific message actually means

The `!ref` property is an internal reference key used by spreadsheet-parsing libraries to describe the used-range of a worksheet. When n8n's Google Sheets node receives a worksheet object that is empty, missing, or otherwise malformed at the API level, the code that expects that key to exist throws this JavaScript error instead of a clean, human-readable message — which is why it looks cryptic compared to the node's usual error formatting.

This has been reported specifically during workflow activation for Row Updated-type triggers, which fits the pattern: activation attempts to read the current worksheet reference to establish a baseline before polling begins, and fails immediately if that reference cannot be constructed.

Check these worksheet-level conditions

  • Open the spreadsheet and compare the tab name to the value stored in the node, character for character. A renamed tab is the most common cause — the spreadsheet ID still resolves, so the credential looks fine, and only the sheet lookup fails.
  • If the node references the sheet by gid rather than by name, confirm the gid still exists. Deleting and recreating a tab with the same name gives it a new gid, which breaks a gid-based reference while leaving a name-based one working.
  • Call spreadsheets.get with the same credential and read the sheets array. It returns every tab with its title, sheetId, and gridProperties — that single response settles whether the tab exists, what it is called, and how many rows and columns it actually has.
  • Check whether the target range has any data. A tab that exists but is completely empty, or a range below the last populated row, can return a response with no values, which is what leaves the parser with an undefined worksheet.

Fix by re-establishing the reference cleanly

Point the node at a tab that exists and a range that contains data, then reactivate. If the tab was renamed, either rename it back or update the node; if it was deleted and recreated, reselect it from the list so n8n stores the current identifier rather than the old one.

Where the spreadsheet is generated by another process, add a guard rather than relying on the tab always being there. Read spreadsheets.get first, confirm the expected title appears in the sheets array, and branch to an alert when it does not. A clear "tab 'Leads' is missing from spreadsheet X" message is worth considerably more at three in the morning than a parser error about !ref.

# Ground truth for tab names, ids, and size
GET https://sheets.googleapis.com/v4/spreadsheets/SPREADSHEET_ID?fields=sheets.properties
Authorization: Bearer ACCESS_TOKEN

# -> { "sheets": [ { "properties": {
#        "sheetId": 0, "title": "Leads", "index": 0,
#        "gridProperties": { "rowCount": 1000, "columnCount": 12 } } } ] }
#    "title" must match the node exactly; "sheetId" is the gid.

# Does the range actually contain anything?
GET https://sheets.googleapis.com/v4/spreadsheets/SPREADSHEET_ID/values/Leads!A1:L

# -> {"range":"Leads!A1:L1000","majorDimension":"ROWS"}
#    no "values" key at all = empty range, which is what leaves the parser
#    holding an undefined worksheet and reading "!ref" off it.

Why this surfaces as a raw JavaScript error instead of a friendly message

n8n's Google Sheets integration, like many spreadsheet tools, relies on a parsing layer that models a worksheet as a set of cells plus a `!ref` key describing the rectangular range those cells occupy — this convention originates from spreadsheet file formats generally, not from Google's API specifically, and n8n's node translates Google's API response into that internal shape before further processing. When Google's API returns a worksheet object that does not map cleanly onto that expected shape (most often because the sheet genuinely has no populated cells, or the API call resolved to an unexpected object entirely), the parsing step that reads `!ref` throws before n8n's own error-handling wrapper gets a chance to translate it into one of its usual descriptive messages. That is the specific mechanical reason this error looks like an internal crash rather than the node's normal validation output.

Recognizing this pattern is useful beyond this one error: any n8n error referencing an internal-looking property name in backticks or with unusual casing (rather than a plain-English description) is generally a sign that the underlying data shape reaching a parsing library did not match what that library expected, and the fix is almost always upstream — at the data or configuration level — rather than something to work around inside n8n itself.

Preventing this on sheets that are actively being restructured

Two habits remove most recurrences. Reference tabs by a name nobody has a reason to change, and keep at least a header row in any tab a workflow reads, so the range is never completely empty. A header row costs nothing and turns "undefined worksheet" into "zero data rows", which downstream nodes handle gracefully.

Beyond that, treat the spreadsheet as an interface with an owner. Sheets that several people edit will get tabs renamed, reordered, and cleared, and no amount of node configuration prevents that. Naming the tab something explicit like "n8n_leads_do_not_rename", and keeping a note of which workflows read it, is a cheaper control than any error handling.

If the error appeared immediately after an n8n upgrade and the spreadsheet is provably unchanged, note your exact version and check the n8n GitHub issues for the Google Sheets nodes before rebuilding anything — parser-level regressions in this area have been reported against specific releases, and pinning or upgrading is a faster fix than reconfiguring a workflow that was already correct.

Checking whether your exact n8n version has a tracked issue for this

Because this error has been reported against at least one specific n8n release, before spending significant time on the worksheet-level checks above, check your installed n8n version against the project's GitHub issues and release notes for the Google Sheets node specifically — searching the exact error string `Cannot read properties of undefined (reading '!ref')` alongside "n8n" surfaces any currently tracked report matching your version range. If a fix has already shipped in a later release, upgrading may resolve the issue directly without needing to diagnose worksheet formatting or data conditions at all, and confirming this first avoids spending time on a workaround for a bug the maintainers have already patched.

A guard that turns the parser error into a useful message

The reason this error costs so much time is that it names an internal implementation detail rather than the thing that is actually wrong. A short guard at the top of the workflow replaces it with a message that names the spreadsheet and the missing tab, which is the difference between a two-minute fix and an hour of reading stack traces.

The guard is one HTTP Request node and one Code node. Fetch the spreadsheet's sheet properties, check that every tab the workflow depends on is present, and throw with a list of the missing ones. Because the properties call is small and cached-friendly, it costs almost nothing against the Sheets quota — one read per run, against a 60-per-minute-per-user ceiling.

Extend the same check to the ranges if the workflow is sensitive to them. gridProperties gives you the tab's rowCount and columnCount, so a range that reaches past the end of the grid can be caught before it is requested rather than after it returns an empty body. Between the two checks, almost every version of this failure becomes a clear sentence in the execution log.

// Code node, fed by GET /v4/spreadsheets/{id}?fields=sheets.properties
const props = $json.sheets.map((s) => s.properties);
const required = ["Leads", "Config"];

const titles = props.map((p) => p.title);
const missing = required.filter((t) => !titles.includes(t));
if (missing.length) {
  throw new Error(
    `Spreadsheet is missing tab(s): ${missing.join(", ")}. Present: ${titles.join(", ")}`
  );
}

const leads = props.find((p) => p.title === "Leads");
if (leads.gridProperties.rowCount < 2) {
  throw new Error("Tab 'Leads' has no data rows — keep at least a header row.");
}

return [{ json: { ok: true, tabs: titles } }];

Sources checked for this guide

Community reports describing this exact error string on activation are limited but consistent in pointing at worksheet-reference issues rather than credential or permission problems.

Frequently asked questions

Is this a permissions error in disguise?

No. It is an internal parsing error thrown when the worksheet reference cannot be read, typically because the selected tab is missing, renamed, or the sheet has no real data — not because access was denied.

Will adding a header row to an empty sheet actually fix this?

In cases where the sheet had genuinely zero data, yes — a valid used-range needs at least some content. If the sheet already has data, look at whether the selected tab itself is stale instead.

Could merged cells in my header row cause this?

It has been reported in adjacent contexts as a contributing factor for unusual used-range responses. If the sheet has merged or protected cells near the top, test unmerging them or moving the range down a row.

I re-selected the sheet and tab and it still fails — what next?

Check your n8n version against known issues for this error string; it has been reported in specific version ranges and may require an upgrade rather than a configuration change.

Is "!ref" a Google Sheets API error?

No. It is an internal key used by the spreadsheet parsing library for a worksheet's used range. Seeing it means the code read a property from an undefined worksheet — the tab or the data it expected was not in the response.

The tab exists and I still get it.

Check whether the requested range contains data. A values request against an empty range returns no "values" key at all, which produces the same undefined worksheet. Keeping a header row in every tab a workflow reads avoids it.