Unable to load Neo4j-Driver (Cannot assign to read only property 'toString' of object '#<Object>')

Please help with using “neo4j-driver” in Code. Many thanks!

Challenge

Neither javascript modules, “neo4j-driver” version 5.28.1 and version 5.18.0 can be loaded via Code node. The error message, " Problem in node ‘Code‘ Cannot assign to read only property ‘toString’ of object '#", persists. See the detailed message below.

The detailed error message?

{
  "errorMessage": "Cannot assign to read only property 'toString' of object '#<Object>'",
  "errorDetails": {},
  "n8nDetails": {
    "n8nVersion": "1.85.4 (Self Hosted)",
    "binaryDataMode": "default",
    "stackTrace": [
      "TypeError: Cannot assign to read only property 'toString' of object '#<Object>'",
      "    at Object.<anonymous> (/usr/local/lib/node_modules/n8n/node_modules/neo4j-driver-core/lib/index.js:45:823)",
      "    at Module._compile (node:internal/modules/cjs/loader:1469:14)",
      "    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)",
      "    at Module.load (node:internal/modules/cjs/loader:1288:32)",
      "    at Module._load (node:internal/modules/cjs/loader:1104:12)",
      "    at Module.require (node:internal/modules/cjs/loader:1311:19)",
      "    at require (node:internal/modules/helpers:179:18)",
      "    at Object.<anonymous> (/usr/local/lib/node_modules/n8n/node_modules/neo4j-driver/lib/driver.js:38:27)",
      "    at Module._compile (node:internal/modules/cjs/loader:1469:14)",
      "    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)"
    ]
  }
}

Workflow

The output returned by the last node

Cannot assign to read only property ‘toString’ of object ‘#’

Information on n8n setup

  • n8n version: 1.85.4 (Self Hosted)
  • Database (default: SQLite): Postgresql
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: macOS 15.3.2

Hi,

i think you might not be returning valid json here:

  const items = [{
      json: {
        totalPersons: personCount
      }
    }];
  const items = [{
      "json": {
        "totalPersons": personCount
      }
    }];

I guess you get this weird error since you are in this try/catch block

Thanks for the thought, but the same error message, “Cannot assign to read only property ‘toString’ of object ‘#’” pops up as modified below.

const neo4j = require('neo4j-driver');
const uri = 'bolt://localhost:7687';
const user = 'neo4j';
const password = 'password';
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password));
const session = driver.session();
const result = await session.run(
      'MATCH (n:Person) RETURN count(n) AS personCount'
    );

const personCount = result.records[0].get('personCount').toNumber();
const items = [{"json": {
    "totalPersons": personCount
  }
}];

return items;

The error seems due to loading the javascript module, “neo4j-driver”. There is no “toString” in the sample code. Could it be a compatibility issue with of loading neo4j-driver into the Code framework?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.