Cannot install 'neo4j-driver/lib/graph-types'

I'm using Server 4.3.2 and developing using JavaScript on an Ubuntu 20.04 machine.

After a system crash, I restarted but the my application server crashed at startup, with the error Cannot find module 'neo4j-driver/lib/graph-types'

I look all around the machine, but there is no file with such a name.

Then I look on the internet and I find the 'official drive for Javascript' on the npm site.

They suggest to npm install neo4j-driver and I have done it but the files is still missing.

I remember that it was part of a neo4j example on how to use neo4j with javascript.

Has anyone some idea on how to retrieve that file?

Thank you

Hi @p.dipietro ,

I think graph-types was a specific file in an older distribution of the driver. For the current driver the imports look different. The top-level neo4j object should encapsulate everything you need.

[Edit/update] OK, so there is still a graph-types in the core package, which is an internal module not meant for public use. neo4j-javascript-driver/graph-types.ts at 4.3 · neo4j/neo4j-javascript-driver · GitHub

Which types are you using? And, are you writing client-side javascript or nodejs?

Best,
ABK

As a minimal example, this jest test imports neo4j then confirms that neo4j.types is a sub-object...

const neo4j = require('neo4j-driver')

describe("neo4j-driver types", () => {
  it("are a sub-object", () => {
    const neo4jTypes = neo4j.types;
    expect(neo4jTypes).toBeDefined();
  })
})

This has inspired a github repo where I'll accumulate minimal viable code examples: GitHub - akollegger/neo4j-js-examples: Collection of minimal viable code snippets which demonstrate so

Hi @abk, I'm writing node.

In the article.js file (which cames from a neo4j example) there is an const neo4j = require('../neo4j).

Into that neo4j.js file there is a const neo4j=require('neo4j-driver').

Now, I have a neo4j-type-handler.js into the middleware folder. The initial lines are

const {
    isDuration,
    isLocalTime,
    isTime,
    isDate,
    isDateTime,
    isLocalDateTime,
    isInt,
    isPoint,
    types,
 } = require('neo4j-driver');
----> const { isNode, isRelationship } = require('neo4j-driver/lib/graph-types')
const { Result } = types

The line marked with an arrow is the offending one: the system crashes.

I deleted that file two days ago, because it was of an old version, without imagining the subsequent mess!

So, the question is how can I patch the program?

If I add const { isNode, isRelationship } = require('neo4j-driver);
when I call the page from the browser it returns the following error:

TypeError: isNode is not a function
   at toNative (/node/app/src/middleware/neo4j-type-handler.js:28:15)
   at /node/app/src/middleware/neo4j-type-handler.js:24:40

and in neo4j-type-handler

...
28    else if ( isNode(value) ) return toNative({
...

I'm really without an idea on how to solve the problem.

Any suggestion will be appreciated.
Thank you
Paolo

OK, isNode does not seem to be public. It's only available in the neo4j-driver-core module, which is described as being for internal use (not end-user). Nevertheless, that's what you'll need to use to get what you need.

I've updated GitHub - akollegger/neo4j-js-examples: Collection of minimal viable code snippets which demonstrate so to use that module. Here's the relevant code snippet for nodejs:

// This is only available from the non-public api...
const {isNode, Node} = require('neo4j-driver-core');

describe("neo4j-driver types", () => {
  describe("Node", () => {
    it("can be constructed", () => {
      const identity = 0;
      const labels = ["A"];
      const properties = {
        k: "value"
      }
      const n = new Node(identity, labels, properties)
      expect(n.identity).toBe(identity);
      expect(n.labels).toEqual(expect.arrayContaining(labels));
      expect(n.properties).toMatchObject(properties);
    })
  })
  it("isNode", () => {
    const identity = 0;
    const labels = ["A"];
    const properties = {
      k: "value"
    }
    const n = new Node(identity, labels, properties)
    expect(isNode(n)).toBeTruthy();
  })
})

Hope that helps.

Best,
ABK

References

Thank you!

IsRelationship is also needed!

My package.json file contains "neo4j-driver": "^4.3.2",

Following the instruction, I run npm install neo4j-driver into my project directory, but I'm not sure that it is the right way.

Which is the easiest way to download and install this new modules?

Paolo

The new module can be added to your project by doing this:

npm install neo4j-driver-core

It'll be important to pay attention to the version in package.json, that both neo4j-driver and
neo4j-driver-core are at the same version.

I've updated the neo4j-js-examples project with usage of isRelationship() and new Relationship().

Best,
ABK