question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trying to use mongoose with node-webkit target on Webpack

See original GitHub issue

I 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:closed
  • Created 8 years ago
  • Comments:19 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mxklabscommented, Mar 5, 2017

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’s package.json in order to populate a version number:

require('fs').readFileSync(__dirname + '/../package.json', 'utf8')

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:

  module: {
    rules: [
      {
        test: /\.js$/,
        loader: "transform-loader?brfs",
        include: path.resolve(__dirname, "node_modules/muri/lib/index.js")
      }
   ]
}

I hope this is useful to someone!

0reactions
croqazcommented, Jan 22, 2016

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:

WARNING in ./~/mongoose/lib/drivers/index.js
Critical dependencies:
8:11-74 the request of a dependency is an expression
 @ ./~/mongoose/lib/drivers/index.js 8:11-74

WARNING in ./~/mongoose/lib/drivers/SPEC.md
Module parse failed: /home/cro/Dev/akasha-electron/node_modules/mongoose/lib/drivers/SPEC.md Line 2: Unexpected token ILLEGAL
You may need an appropriate loader to handle this file type.
| 
| # Driver Spec
| 
| TODO
 @ ./~/mongoose/lib/drivers ^\.\/.*$
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found