Trying to use mongoose with node-webkit target on Webpack
See original GitHub issueI tried to get an answer on StackOverflow, but nobody seemed to have an idea. So I post this as a bug, since I can’t get it to work:
I use webpack and target it’s build output for node-webkit
. I want to require the mongoose
module inside my project to connect to mongodb, but it always states some errors when I try to pack the project:
WARNING in ./~/mongoose/~/mongodb/~/mongodb-core/~/bson/~/bson-ext/ext/index.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./win32/x64/bson in /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/ext
@ ./~/mongoose/~/mongodb/~/mongodb-core/~/bson/~/bson-ext/ext/index.js 6:10-37
WARNING in ./~/mongoose/~/mongodb/~/mongodb-core/~/bson/~/bson-ext/ext/index.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./win32/ia32/bson in /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/ext
@ ./~/mongoose/~/mongodb/~/mongodb-core/~/bson/~/bson-ext/ext/index.js 8:10-38
WARNING in ./~/mongoose/~/mongodb/~/mongodb-core/~/bson/~/bson-ext/ext/index.js
Module not found: Error: Cannot resolve 'file' or 'directory' ../build/Release/bson in /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/ext
@ ./~/mongoose/~/mongodb/~/mongodb-core/~/bson/~/bson-ext/ext/index.js 10:10-42 15:9-41
ERROR in ./~/mongoose/~/mongodb/~/mongodb-core/~/kerberos/lib/kerberos.js
Module not found: Error: Cannot resolve 'file' or 'directory' ../build/Release/kerberos in /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/lib
@ ./~/mongoose/~/mongodb/~/mongodb-core/~/kerberos/lib/kerberos.js 1:15-51
ERROR in ./~/mongoose/~/mongodb/~/mongodb-core/~/kerberos/lib/win32/wrappers/security_credentials.js
Module not found: Error: Cannot resolve 'file' or 'directory' ../../../build/Release/kerberos in /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/lib/win32/wrappers
@ ./~/mongoose/~/mongodb/~/mongodb-core/~/kerberos/lib/win32/wrappers/security_credentials.js 1:32-74
ERROR in ./~/mongoose/~/mongodb/~/mongodb-core/~/kerberos/lib/win32/wrappers/security_context.js
Module not found: Error: Cannot resolve 'file' or 'directory' ../../../build/Release/kerberos in /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/lib/win32/wrappers
@ ./~/mongoose/~/mongodb/~/mongodb-core/~/kerberos/lib/win32/wrappers/security_context.js 1:28-70
ERROR in ./~/mongoose/~/mongodb/~/mongodb-core/~/kerberos/lib/win32/wrappers/security_buffer.js
Module not found: Error: Cannot resolve 'file' or 'directory' ../../../build/Release/kerberos in /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/lib/win32/wrappers
@ ./~/mongoose/~/mongodb/~/mongodb-core/~/kerberos/lib/win32/wrappers/security_buffer.js 1:27-69
ERROR in ./~/mongoose/~/mongodb/~/mongodb-core/~/kerberos/lib/win32/wrappers/security_buffer_descriptor.js
Module not found: Error: Cannot resolve 'file' or 'directory' ../../../build/Release/kerberos in /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/lib/win32/wrappers
@ ./~/mongoose/~/mongodb/~/mongodb-core/~/kerberos/lib/win32/wrappers/security_buffer_descriptor.js 1:37-79
It seems like webpack is unable to load .node
files, so I installed the node-loader
and added to my webpack.config.js:
module.exports = {
entry: './ui/index.jsx',
target: 'node-webkit',
output: {
path: __dirname + '/build-ui',
filename: 'app.js',
publicPath: '/assets/'
},
module: {
loaders: [
{
test: /\.jsx$/,
loader: 'jsx-loader?insertPragma=React.DOM&harmony'
},
{
test: /\.css$/,
loader: "style-loader!css-loader"
},
{
test: /\.scss$/,
loader: "style-loader!css-loader!sass-loader"
},
{
test: /\.(png|jpg)$/,
loader: 'url-loader?limit=8192'
},
{
test: /\.json$/,
loader: "json-loader"
},
{
test: /\.target.mk$/,
loader: "raw-loader"
},
{
test: /\.node$/,
loader: "node-loader"
}
]
},
resolve: {
extensions: ['', '.js', '.jsx']
}
};
But it still throws that errors and warnings. Am I missing something? Or is this a bug?
Issue Analytics
- State:
- Created 8 years ago
- Comments:19 (1 by maintainers)
Top Results From Across the Web
Trying to use mongoose with node-webkit target on Webpack
I use webpack and target it's build output for node-webkit . I want to require the mongoose module inside my project to connect...
Read more >Trying to use mongoose with node-webkit target on Webpack ...
Coding example for the question Trying to use mongoose with node-webkit target on Webpack-node.js.
Read more >Target - webpack 3 documentation
webpack can compile for multiple environments or targets. To understand what a target is in detail, read through the targets concept page.
Read more >Mongoose v6.8.0: Browser Library
If you're bundling your code with Webpack, you should be able to import ... You can use the below syntax to access the...
Read more >Which database (NeDB/PouchDB) is the best for a node ...
If you have tabular data (monthly reports sound like this), you may use the built-in sql database of node-webkit: SQLite. For most cases,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m not sure how helpful this is to anybody but I’ve been stuck on this issue (web-packing mongoose) for some time and came up with a resolution I’ve not seen mentioned here, so I thought I’d share it.
The primary issue I’ve been stuck on is web-packing muri, a dependency of mongoose. This is because
node_modules/muri/lib/index.js
reads muri’spackage.json
in order to populate a version number:The reason this was a problem for me is that after webpack does its business the resulting javascript file still wants to read muri’s
package.json
but fails miserably.I’ve resolved this by using a browserify webpack loader (brfs) which embeds files read by the fs module into the code. For details on how to use this in webpack read this.
Note that the following rule helped me successfully pack muri:
I hope this is useful to someone!
Found the problem !! The “kerberos” dependency was not installed correctly. I tried to require the module by hand and I couldn’t. I tried to install it and i had error from https://github.com/christkv/kerberos/issues/21 ; I installed “libkrb5-dev”, then installed “kerberos” again and now mongoose works with just 1 warning: