首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将Neo4j Javascript驱动程序导入角2 CLI时出错

将Neo4j Javascript驱动程序导入角2 CLI时出错
EN

Stack Overflow用户
提问于 2016-10-22 14:30:13
回答 1查看 854关注 0票数 1

头盔,我有一些模块没有发现错误,而试图使用Neo4j驱动程序在我的角度2 CLI应用程序。

我可能漏掉了什么东西试图导入它。

  • 我安装它的时候:ng安装了新4j驱动程序
  • 在我的service.ts:import 'neo4j-driver/lib/browser/neo4j-web';
  • 试图在服务中调用此示例代码: getFromDB():void{ var neo4j =需要量(‘ne4j-neo4j’).v1;var driver = neo4j.driver("bolt: // localhost",neo4j.auth.basic("neo4j","pisikopat"));//创建一个会话来运行Cypher语句。//注意:始终确保在使用完会话后关闭它们!var session = driver.session ();//运行Cypher语句,在记录到达时以流式方式读取结果:.run(“可选匹配(源)-r-(目标)”,其中r不是空返回(源)“) .subscribe({ onNext: function (record) { console.log(record._fields);},onCompleted: function (){ // Completed!session.close();},onError:函数(错误){console.log(错误);}};}

当我ng服务我的应用程序时,我会得到以下错误:

代码语言:javascript
复制
ERROR in ./~/neo4j-driver/lib/v1/internal/ch-node.js
Module not found: Error: Can't resolve 'net' in 'E:\emek\node_modules\neo4j-driver\lib\v1\internal'
 @ ./~/neo4j-driver/lib/v1/internal/ch-node.js 32:11-25 364:2-24
 @ ./~/neo4j-driver/lib/v1/internal/connector.js
 @ ./~/neo4j-driver/lib/v1/driver.js
 @ ./~/neo4j-driver/lib/v1/index.js
 @ ./~/neo4j-driver/lib/index.js
 @ ./src/app/services/heroes.service.ts
 @ ./src/app/app.component.ts
 @ ./src/app/index.ts
 @ ./src/main.ts
 @ multi main

ERROR in ./~/neo4j-driver/lib/v1/internal/ch-node.js
Module not found: Error: Can't resolve 'tls' in 'E:\emek\node_modules\neo4j-driver\lib\v1\internal'
 @ ./~/neo4j-driver/lib/v1/internal/ch-node.js 36:11-25
 @ ./~/neo4j-driver/lib/v1/internal/connector.js
 @ ./~/neo4j-driver/lib/v1/driver.js
 @ ./~/neo4j-driver/lib/v1/index.js
 @ ./~/neo4j-driver/lib/index.js
 @ ./src/app/services/heroes.service.ts
 @ ./src/app/app.component.ts
 @ ./src/app/index.ts
 @ ./src/main.ts
 @ multi main

ERROR in ./~/neo4j-driver/lib/v1/internal/ch-node.js
Module not found: Error: Can't resolve 'readline' in 'E:\emek\node_modules\neo4j-driver\lib\v1\internal'
 @ ./~/neo4j-driver/lib/v1/internal/ch-node.js 92:2-21
 @ ./~/neo4j-driver/lib/v1/internal/connector.js
 @ ./~/neo4j-driver/lib/v1/driver.js
 @ ./~/neo4j-driver/lib/v1/index.js
 @ ./~/neo4j-driver/lib/index.js
 @ ./src/app/services/heroes.service.ts
 @ ./src/app/app.component.ts
 @ ./src/app/index.ts
 @ ./src/main.ts
 @ multi main

角-cli: 1.0.0-beta.15节点:4.5.0os: win32 x64

EN

回答 1

Stack Overflow用户

发布于 2017-05-18 22:10:46

这可能有点晚了,但无论如何都到了。

首先,您需要改变导入和分配驱动程序的方式。更改:

代码语言:javascript
复制
import 'neo4j-driver/lib/browser/neo4j-web';

至:

代码语言:javascript
复制
import * as neo4j_driver from 'neo4j-driver/lib/browser/neo4j-web.min.js';

然后更改节点外观语法:

代码语言:javascript
复制
var neo4j = require('neo4j-driver').v1;

至:

代码语言:javascript
复制
const neo4j = neo4j_driver.v1;

这将消除您所犯的错误。

然后,实际上您可能会因为没有在uri中分配端口而出现错误。为了获得正确的端口(7474对我不起作用),我启动了DB并转到localhost:7474的Neo4j浏览器。然后,您必须向下查看页面,其中写着“您作为用户neo4j连接到服务器螺栓://localhost:7687”--我不确定这是默认的还是被分配的,但无论如何。

然后,我在uri中使用了这个端口,而且所有东西现在都在角内工作(尽管如果使用远程连接(例如使用Graphene,并且我找到的唯一文档不适用于JS驱动程序),则无法使其工作)。

以下是我的完整解决方案:

代码语言:javascript
复制
import {Component, OnInit} from '@angular/core';
import * as neo4j_driver from 'neo4j-driver/lib/browser/neo4j-web.min.js';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  title = 'app works!';

  constructor() {
  }

  ngOnInit() {
    const neo4j = neo4j_driver.v1;
    const uri = 'bolt://localhost:7687';
    const user = 'neo4j';
    const password = '<your password>';
    const driver = neo4j.driver(uri, neo4j.auth.basic(user, password), {maxTransactionRetryTime: 15000});

    // Register a callback to know if driver creation was successful:
    driver.onCompleted = function () {
    // proceed with using the driver, it was successfully instantiated
    };
    // Register a callback to know if driver creation failed.
    // This could happen due to wrong credentials or database unavailability:
    driver.onError = function (error) {
      console.log('Driver instantiation failed', error);
    };

    const session = driver.session();
    const result = session.run('MATCH (a:Person) RETURN a.name ORDER BY a.name');
    const people = [];

    result.subscribe({
      onNext: record => {
        const name = record.get(0);
        people.push(name);
      },
      onCompleted: () => {
        session.close();
        console.log(people);
      },
      onError: error => {
        console.log(error);
      }
    });
  }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40193307

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档