【发布时间】:2018-02-06 10:58:59
【问题描述】:
我正在尝试在我的node.js 项目中使用neo4j-driver:
var neo4j = require('neo4j-driver').v1;
// neo4j cypher helper module
const USERNAME = "neo4j";
const PASSWORD = "neo4j";
const URI = "bolt://localhost:7687";
const driver = neo4j.driver(URI, neo4j.auth.basic(USERNAME, PASSWORD));
const session = driver.session();
当我运行 webpack 时,它给了我以下错误:
./node_modules/neo4j-driver/lib/v1/internal/host-name-resolvers.js 中的错误 找不到模块:错误:无法解析“/home/nikita/Desktop/kipnis_prototype/BrainImmuneConnectome/node_modules/neo4j-driver/lib/v1/internal”中的“dns”
readline、tls、net 的类似错误。怎么解决?
我的webpack.config.js:
var path = require('path');
module.exports = {
entry: {
app: './views/index.js'
//vendor: ["react","react-dom"]
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, './public')
},
devtool: "#eval-source-map",
module: {
rules: [{
test: /\.jsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader?cacheDirectory=true',
}
}]
},
node: {
fs: 'empty'
},
resolve: {
extensions: ['.js', '.jsx']
}
};
我确信数据库一切正常。错误类似于以下github线程:
https://github.com/neo4j/neo4j-javascript-driver/issues/192
但是,我的导入是正确的,所以我很困惑。
更新
安装loader-utils 并没有解决这个问题:
Why can't webpack find any module from my React Webapp?
更新
提供neo4j-driver的整个路径后:
var neo4j_driver = require('../node_modules/neo4j-driver/lib/browser/neo4j-web.min.js');
webpack 运行良好,所以我想它现在可以找到驱动程序,但是,当我尝试运行应用程序时,会显示另一个错误:
Neo4jError: Fatal: No compatible transport available. Need to run on a
platform with the WebSocket API.
更新
我发现我无法指定整个路径,无论如何它应该是require("neo4j-driver")。然后在以下链接中:
https://github.com/request/request/compare/master...pho3nixf1re:webpack-tests
externals 部分在webpack 配置文件中指定:
...
externals: {
fs: '{}',
tls: '{}',
net: '{}',
console: '{}'
}
将此部分添加到我的webpack.config.js 允许在node.js 控制台中运行webpack 和应用程序而不会出现错误,但是,在这种情况下,浏览器会生成另一个错误,这显然与neo4j-driver 有关:
更新
上面Update中之前的错误是由于不适当的node.js模块导入导致的,所以在修复应用程序开始正常工作后,问题现在解决了。
【问题讨论】: