尝试在Webpack上将mongoose与node

尝试在Webpack上将mongoose与node

本文介绍了尝试在Webpack上将mongoose与node-webkit目标一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用webpack并将其目标定位为node-webkit的构建输出.我想要求项目中的mongoose模块连接到mongodb,但是当我尝试打包项目时,它总是会指出一些错误:

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

似乎webpack无法加载.node文件,因此我安装了node-loader并将其添加到我的webpack.config.js中:

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?

推荐答案

显示错误详细信息后,错误很明显.

After displaying error details the error was pretty clear.

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
resolve file
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/ext/win32/x64/bson doesn't exist
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/ext/win32/x64/bson.js doesn't exist
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/ext/win32/x64/bson.jsx doesn't exist
resolve directory
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/ext/win32/x64/bson doesn't exist (directory default file)
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/ext/win32/x64/bson/package.json doesn't exist (directory description file)
[/Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/ext/win32/x64/bson]
[/Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/ext/win32/x64/bson.js]
[/Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/ext/win32/x64/bson.jsx]
 @ ./~/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
resolve file
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/ext/win32/ia32/bson doesn't exist
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/ext/win32/ia32/bson.js doesn't exist
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/ext/win32/ia32/bson.jsx doesn't exist
resolve directory
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/ext/win32/ia32/bson doesn't exist (directory default file)
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/ext/win32/ia32/bson/package.json doesn't exist (directory description file)
[/Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/ext/win32/ia32/bson]
[/Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/ext/win32/ia32/bson.js]
[/Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/ext/win32/ia32/bson.jsx]
 @ ./~/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
resolve file
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/build/Release/bson doesn't exist
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/build/Release/bson.js doesn't exist
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/build/Release/bson.jsx doesn't exist
resolve directory
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/build/Release/bson doesn't exist (directory default file)
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/build/Release/bson/package.json doesn't exist (directory description file)
[/Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/build/Release/bson]
[/Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/build/Release/bson.js]
[/Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/build/Release/bson.jsx]
 @ ./~/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
resolve file
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos doesn't exist
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos.js doesn't exist
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos.jsx doesn't exist
resolve directory
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos doesn't exist (directory default file)
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos/package.json doesn't exist (directory description file)
[/Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos]
[/Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos.js]
[/Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos.jsx]
 @ ./~/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
resolve file
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos doesn't exist
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos.js doesn't exist
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos.jsx doesn't exist
resolve directory
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos/package.json doesn't exist (directory description file)
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos doesn't exist (directory default file)
[/Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos]
[/Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos.js]
[/Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos.jsx]
 @ ./~/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
resolve file
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos doesn't exist
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos.js doesn't exist
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos.jsx doesn't exist
resolve directory
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos/package.json doesn't exist (directory description file)
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos doesn't exist (directory default file)
[/Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos]
[/Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos.js]
[/Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos.jsx]
 @ ./~/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
resolve file
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos doesn't exist
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos.js doesn't exist
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos.jsx doesn't exist
resolve directory
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos/package.json doesn't exist (directory description file)
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos doesn't exist (directory default file)
[/Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos]
[/Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos.js]
[/Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos.jsx]
 @ ./~/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
resolve file
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos doesn't exist
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos.js doesn't exist
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos.jsx doesn't exist
resolve directory
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos/package.json doesn't exist (directory description file)
  /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos doesn't exist (directory default file)
[/Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos]
[/Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos.js]
[/Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build/Release/kerberos.jsx]
 @ ./~/mongoose/~/mongodb/~/mongodb-core/~/kerberos/lib/win32/wrappers/security_buffer_descriptor.js 1:37-79

所以我只是忘了将.node添加到resolve.extensions数组中.

So I just forgot to add .node to the resolve.extensions array.

这篇关于尝试在Webpack上将mongoose与node-webkit目标一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 06:11