Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing Modules #192

Closed
hollandThomas opened this issue Jan 19, 2017 · 9 comments
Closed

Missing Modules #192

hollandThomas opened this issue Jan 19, 2017 · 9 comments

Comments

@hollandThomas
Copy link

Hey,

when I'm trying to bundle my package with webpack it says:

WARNING in ./~/neo4j-driver/lib/v1/internal/features.js
Module not found: Error: Cannot resolve module 'tls' in [some local path on my machine]/node_modules/neo4j-driver/lib/v1/internal
 @ ./~/neo4j-driver/lib/v1/internal/features.js 34:17-31

WARNING in ./~/neo4j-driver/lib/external/es6-promise.js
Module not found: Error: Cannot resolve module 'vertx' in [some local path on my machine]/node_modules/neo4j-driver/lib/external
 @ ./~/neo4j-driver/lib/external/es6-promise.js 132:18-28

ERROR in ./~/neo4j-driver/lib/v1/internal/ch-node.js
Module not found: Error: Cannot resolve module 'net' in [some local path on my machine]/node_modules/neo4j-driver/lib/v1/internal
 @ ./~/neo4j-driver/lib/v1/internal/ch-node.js 32:11-25 355:2-24

ERROR in ./~/neo4j-driver/lib/v1/internal/ch-node.js
Module not found: Error: Cannot resolve module 'tls' in [some local path on my machine]/chat/node_modules/neo4j-driver/lib/v1/internal
 @ ./~/neo4j-driver/lib/v1/internal/ch-node.js 36:11-25

ERROR in ./~/neo4j-driver/lib/v1/internal/ch-node.js
Module not found: Error: Cannot resolve module 'fs' in [some local path on my machine]/node_modules/neo4j-driver/lib/v1/internal
 @ ./~/neo4j-driver/lib/v1/internal/ch-node.js 40:10-23

ERROR in ./~/neo4j-driver/lib/v1/internal/ch-node.js
Module not found: Error: Cannot resolve module 'readline' in [some local path on my machine]/node_modules/neo4j-driver/lib/v1/internal
 @ ./~/neo4j-driver/lib/v1/internal/ch-node.js 90:2-21

This makes using the driver impossible and shuts down my whole application. I did try to install each of the listed modules manually. This resolved everything except for the 'fs' module error. Also I feel that this shouldn't be necessary. Any hints? Thank you!

@lutovich
Copy link
Contributor

Hi @hollandThomas,

Could you maybe share your webpack config or even the whole project? We will try to reproduce then.

@hollandThomas
Copy link
Author

hollandThomas commented Jan 19, 2017

Hi @lutovich,

sharing the whole project would be difficult but here are the important bits:

webpack config, nothing fancy:

const path = require('path');
const webpack = require('webpack');

module.exports = {
  devtool: 'cheap-module-eval-source-map',
  entry: [
    'webpack-hot-middleware/client',
    './client/src/index.js',
  ],
  output: {
    path: path.join(__dirname, 'client/dist'),
    filename: 'bundle.js',
    publicPath: '/static/',
  },
  eslint: {
    configFile: './.eslintrc',
  },
  jest: {
    setupFiles: ['./jest.config.js'],
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
  ],
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: 'babel',
        include: path.join(__dirname, 'client/src'),
      }, {
        test: /\.css$/,
        include: /node_modules/,
        loaders: ['style-loader', 'css-loader'],
      },
    ],
  },
};

project dependencies:

"dependencies": {
    "babel-cli": "^6.18.0",
    "babel-core": "^6.18.2",
    "babel-eslint": "^7.1.1",
    "babel-jest": "^18.0.0",
    "babel-loader": "^6.2.8",
    "babel-plugin-react-transform": "^2.0.2",
    "babel-plugin-transform-flow-strip-types": "^6.18.0",
    "babel-polyfill": "^6.16.0",
    "babel-preset-es2015": "^6.18.0",
    "babel-preset-latest": "^6.16.0",
    "babel-preset-react": "^6.16.0",
    "babel-preset-stage-0": "^6.16.0",
    "babel-relay-plugin": "^0.10.0",
    "body-parser": "^1.16.0",
    "chalk": "^1.1.3",
    "compression-webpack-plugin": "^0.3.2",
    "css-loader": "^0.26.0",
    "enzyme": "^2.7.0",
    "eslint": "^3.13.1",
    "eslint-config-airbnb": "^14.0.0",
    "eslint-plugin-import": "^2.2.0",
    "eslint-plugin-jsx-a11y": "^3.0.2",
    "eslint-plugin-react": "^6.9.0",
    "express": "^4.14.0",
    "express-graphql": "^0.6.1",
    "flow-bin": "^0.38.0",
    "graphql": "^0.8.2",
    "graphql-relay": "^0.4.4",
    "immutable": "^3.8.1",
    "ioredis": "^2.5.0",
    "jest": "^18.1.0",
    "jest-cli": "^18.1.0",
    "jsonwebtoken": "^7.2.1",
    "lodash": "^4.17.4",
    "neo4j-driver": "^1.0.5",
    "nodemon": "^1.11.0",
    "passport": "^0.3.2",
    "passport-jwt": "^2.2.1",
    "passport-local": "^1.0.0",
    "react": "^15.4.2",
    "react-addons-test-utils": "^15.4.2",
    "react-dom": "^15.4.2",
    "react-hot-loader": "^1.3.1",
    "react-icons": "^2.2.1",
    "react-redux": "^5.0.2",
    "react-relay": "^0.10.0",
    "react-router": "^3.0.2",
    "react-router-relay": "^0.13.5",
    "react-test-renderer": "^15.4.2",
    "react-transform-hmr": "^1.0.4",
    "redis": "^2.6.5",
    "redux": "^3.6.0",
    "redux-devtools": "^3.3.2",
    "redux-devtools-extension": "^1.0.0",
    "redux-immutable": "^3.0.10",
    "sanitize.css": "^4.1.0",
    "style-loader": "^0.13.1",
    "styled-components": "^1.3.1",
    "stylelint": "^7.6.0",
    "stylelint-config-standard": "^15.0.0",
    "stylelint-processor-styled-components": "^0.0.4",
    "webpack": "^1.13.3",
    "webpack-dev-middleware": "^1.8.4",
    "webpack-dev-server": "^1.16.2",
    "webpack-hot-middleware": "^2.13.2"
  }

Usually we would use the driver on our graphql backend but for early testing purposes we run some test code featuring the driver that looks something like this (I tried to reduce it to the bare minimum):

import React, { Component } from 'react';
import neo4j from 'neo4j-driver';

export default class Test extends Component {
  getData = (userId) => {
    const driver = neo4j.driver(
      'our bolt endpoint',
      neo4j.auth.basic('username', 'password'),
    );
    const session = driver.session();
    session
    .run(`MATCH (user:User)-[:PUBLISHED_MESSAGE]->(messages:Message) WHERE user.id = ${userId} RETURN messages`)
    .then((result) => {
      result.records.forEach((record) => {
        console.log(record._fields);
      });
      session.close();
    })
    .catch((error) => {
      console.log(error);
    });
  }

  render() {
    return (
        <input type="Button" onClick={this.getData(10)} value="Get Data"/>
    );
  }
}

Let me know if you need more information. Thank you.

@hollandThomas
Copy link
Author

hollandThomas commented Jan 20, 2017

I did some digging and ended up in these issues: request/request#1529 and socketio/socket.io-client#933

I have a feeling that these might be related in some way. I tried some of the presented solutions. These got rid of the errors but left me with a blank page when accessing localhost. Maybe this will help someone more technically apt than me to find the solution to this specific problem.

Specifically, the webpack docs write about both setting a target environment and including polyfills for various node stuff.
This does leave the impression of being the solution especially for our case of running the neo4j-driver in our client code solely for initial test purposes but apparently it is not. More, using the driver in our express server which in fact should not need to be led to believe to be in a node environment also results in non-functionality.

I will add that it is entirely possible that I am missing out on some critical fundamentals regarding any of the involved technologies since I am rather new to all of them. It would however be tragic if this is what keeps us from using neo4j. It seems to fit our use case perfectly.

@hollandThomas
Copy link
Author

Alright nevermind ... the devil's in the details and sometimes it's the easy things.

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

instead of

import neo4j from 'neo4j-driver';

does the trick. I'd like github to have a 🤦 smiley.

@Ynoaparast
Copy link

Ynoaparast commented Dec 17, 2017

Hi,

I seem to be knocking my head against this issue as well, although I did change it to

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

ERROR in ./~/neo4j-driver/lib/v1/internal/ch-node.js Module not found: Error: Can't resolve 'net' in 'G:\LocalPath\SolutionName\ProjectName\node_modules\neo4j-driver\lib\v1\internal' @ ./~/neo4j-driver/lib/v1/internal/ch-node.js 15:11-25 425: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 @ ./ClientApp/app/components/counter/counter.component.ts @ ./ClientApp/app/app.shared.module.ts @ ./ClientApp/app/app.browser.module.ts @ ./ClientApp/boot.browser.ts @ multi event-source-polyfill webpack-hot-middleware/client?path=__webpack_hmr&dynamicPublicPath=true ./ClientApp/boot.browser.ts

ERROR in ./~/neo4j-driver/lib/v1/internal/ch-node.js Module not found: Error: Can't resolve 'tls' in 'G:\LocalPath\SolutionName\ProjectName\node_modules\neo4j-driver\lib\v1\internal' @ ./~/neo4j-driver/lib/v1/internal/ch-node.js 19: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 @ ./ClientApp/app/components/counter/counter.component.ts @ ./ClientApp/app/app.shared.module.ts @ ./ClientApp/app/app.browser.module.ts @ ./ClientApp/boot.browser.ts @ multi event-source-polyfill webpack-hot-middleware/client?path=__webpack_hmr&dynamicPublicPath=true ./ClientApp/boot.browser.ts

ERROR in ./~/neo4j-driver/lib/v1/internal/ch-node.js Module not found: Error: Can't resolve 'fs' in 'G:\LocalPath\SolutionName\ProjectName\node_modules\neo4j-driver\lib\v1\internal' @ ./~/neo4j-driver/lib/v1/internal/ch-node.js 23:10-23 @ ./~/neo4j-driver/lib/v1/internal/connector.js @ ./~/neo4j-driver/lib/v1/driver.js @ ./~/neo4j-driver/lib/v1/index.js @ ./~/neo4j-driver/lib/index.js @ ./ClientApp/app/components/counter/counter.component.ts @ ./ClientApp/app/app.shared.module.ts @ ./ClientApp/app/app.browser.module.ts @ ./ClientApp/boot.browser.ts @ multi event-source-polyfill webpack-hot-middleware/client?path=__webpack_hmr&dynamicPublicPath=true ./ClientApp/boot.browser.ts

ERROR in ./~/neo4j-driver/lib/v1/internal/ch-node.js Module not found: Error: Can't resolve 'readline' in 'G:\LocalPath\SolutionName\ProjectName\node_modules\neo4j-driver\lib\v1\internal' @ ./~/neo4j-driver/lib/v1/internal/ch-node.js 95: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 @ ./ClientApp/app/components/counter/counter.component.ts @ ./ClientApp/app/app.shared.module.ts @ ./ClientApp/app/app.browser.module.ts @ ./ClientApp/boot.browser.ts @ multi event-source-polyfill webpack-hot-middleware/client?path=__webpack_hmr&dynamicPublicPath=true ./ClientApp/boot.browser.ts

ERROR in /~/neo4j-driver/lib/v1/internal/host-name-resolvers.js Module not found: Error: Can't resolve 'dns' in 'G:\LocalPath\SolutionName\ProjectName\node_modules\neo4j-driver\lib\v1\internal' @ ./~/neo4j-driver/lib/v1/internal/host-name-resolvers.js 92:18-32 @ ./~/neo4j-driver/lib/v1/internal/connection-providers.js @ ./~/neo4j-driver/lib/v1/driver.js @ ./~/neo4j-driver/lib/v1/index.js @ ./~/neo4j-driver/lib/index.js @ ./ClientApp/app/components/counter/counter.component.ts @ ./ClientApp/app/app.shared.module.ts @ ./ClientApp/app/app.browser.module.ts @ ./ClientApp/boot.browser.ts @ multi event-source-polyfill webpack-hot-middleware/client?path=__webpack_hmr&dynamicPublicPath=true ./ClientApp/boot.browser.ts
`

I'm using Visual Studio 2017 ASP.NET Core to create an Angular 2 application and assumed using the Neo4J Javascript driver was necessary, but I can't make it work. It's either giving me 'implicity any' errors, 'module declaration not found' or this 'module not found' error.

counter.component.ts:

import { Component } from "@angular/core";

@Component({ selector: 'counter', templateUrl: './counter.component.html' }) export class CounterComponent { public currentCount = 0;

public incrementCounter() {
    this.currentCount++;

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

    const driver = neo4j.driver("bolt://localhost:7687", neo4j.auth.basic("", ""));
    const session = driver.session();

    const personName = 'Alice';
    const resultPromise = session.run(
        'CREATE (a:Person {name: $name}) RETURN a',
        { name: personName }
    );

    resultPromise.then((result: any) => {
        (session as any).close();

        const singleRecord: any = (result as any).records[0];
        const node: any = (singleRecord as any).get(0);

        console.log(node.properties.name);

        // on application exit:
        (driver as any).close();
    });
}

}
`

Any help appreciated!

Kind Regards

@lutovich
Copy link
Contributor

Hi @Ynoaparast,

Could you please try solution mentioned here #152 (comment)?

@Ynoaparast
Copy link

Hi @lutovich

It worked like charm. However, I still get the errors when I try to mange the Angular 2 App through Visual Studio 2017. Looks like I'll just do it like this for now.
Thanks for the help :)

@Ynoaparast
Copy link

and the driver!

@Alex0007
Copy link

For anyone who tries to use neo4j-driver with typescript on frontend

  1. Add file

neo4j-driver.d.ts

/**
 * Hack to reuse neo4j-driver types for neo4j-web
 */
declare module 'neo4j-driver/lib/browser/neo4j-web' {
    import a = require('neo4j-driver');
    export = a;
}
  1. And then use neo4j as
import { v1 as neo4j } from "neo4j-driver/lib/browser/neo4j-web";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants