2016-10-22 2 views
1

Helloes、 モジュールが見つかりません Angular 2 CLIアプリケーションでNeo4jドライバを使用しようとしているときにエラーが発生しました。Neo4j JavascriptドライバをAngular 2 CLIにインポートする際にエラーが発生しました

インポートしようとしているものが見つからない可能性があります。

  • 私はそれをインストール:ngの私のservice.tsでのNeo4j-ドライバ
  • をインストール

    getFromDB(): void { 
        var neo4j = require('neo4j-driver').v1; 
        var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "pisikopat")); 
    
        // Create a session to run Cypher statements in. 
        // Note: Always make sure to close sessions when you are done using them! 
        var session = driver.session(); 
    
        // Run a Cypher statement, reading the result in a streaming manner as records arrive: 
        session 
        .run("OPTIONAL MATCH (source)-[r]-(target) WHERE r is not null RETURN (source)") 
        .subscribe({ 
         onNext: function (record) { 
         console.log(record._fields); 
         }, 
         onCompleted: function() { 
         // Completed! 
         session.close(); 
         }, 
         onError: function (error) { 
         console.log(error); 
         } 
        }); 
    } 
    
:サービスでは、このサンプルコードを呼び出そうとimport 'neo4j-driver/lib/browser/neo4j-web';
  • ngが私のアプリケーションになると、次のエラーが表示されます。

    角度-CLI
    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 
    

    :1.0.0-beta.15 ノード:4.5.0 OS:Win32のx64の

  • 答えて

    1

    これは少し遅くなるかもしれませんが、ここではとにかくです。

    まず、ドライバをインポートして割り当てる方法を変更する必要があります。 変更を行います。

    import 'neo4j-driver/lib/browser/neo4j-web'; 
    

    :へ

    var neo4j = require('neo4j-driver').v1; 
    

    import * as neo4j_driver from 'neo4j-driver/lib/browser/neo4j-web.min.js'; 
    

    次にノード探して構文を変更

    const neo4j = neo4j_driver.v1; 
    

    これはエラーを取り除くでしょう、あなたが持ってる。

    次に、あなたのuriにポートを割り当てないと、実際にはエラーが発生するかもしれません。正しいポート(7474が私のために働かなかった)を得るために、私はDBを起動し、localhost:7474でNeo4jブラウザに行きました。 「あなたはユーザーneo4j としてサーバーに接続しています。ボルト:// localhost:7687」と表示されているページを見下す必要があります。デフォルトであるか、それとも割り当てられているかはわかりません。

    私はuriでこのポートを使用しましたが、すべてAngularの中で動作します(Grapheneなどのリモート接続を使用している場合は動作しませんが、私が見つけることができる唯一のドキュメントはJSドライバ)。ここで

    は私の完全なソリューションです:

    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); 
         codes.push(name); 
         }, 
         onCompleted:() => { 
         session.close(); 
         console.log(people); 
         }, 
         onError: error => { 
         console.log(error); 
         } 
        }); 
        } 
    } 
    
    関連する問題