Webpack的依赖请求是一个expression式

我正在testing我的新安装程序,为此我编译了一个如下所示的服务器端脚本:

import mongoose from 'mongoose'; import User from './models/UserSchema.jsx'; var connStr = 'mongodb://localhost:27017/mongoose-bcrypt-test'; mongoose.connect(connStr, function(err) { if (err) throw err; console.log('Successfully connected to MongoDB'); }); // create a user a new user var testUser = new User({ username: 'jmar777', password: 'Password123' }); // save user to database testUser.save(function(err) { if (err) throw err; // attempt to authenticate user User.getAuthenticated('jmar777', 'Password123', function(err, user, reason){ if (err) throw err; // login was successful if we have a user if (user) { // handle login success console.log('login success'); return; } // otherwise we can determine why we failed var reasons = User.failedLogin; switch (reason) { case reasons.NOT_FOUND: case reasons.PASSWORD_INCORRECT: // note: these cases are usually treated the same - don't tell // the user *why* the login failed, only that it did break; case reasons.MAX_ATTEMPTS: // send email or otherwise notify user that account is // temporarily locked break; } }); }); 

我正在使用webpack,这个configuration:

 module.exports = { entry: './testing.js', module: { loaders: [ { exclude: /node_modules/, loader: 'babel', query: { plugins: ['./build/babelRelayPlugin'], }, test: /\.jsx?$/ }, { loader: 'node-loader', test: /\.node$/, }, { loader: 'json-loader', test: /\.json$/, }, { loader: 'raw-loader', test: /\.md/, }, ] }, output: { filename: 'app.js', path: __dirname }, // resolve: { // extensions: ["", ".js", ".jsx", ".node", ".webpack-loader.js", ".web-loader.js", ".loader.js"] // }, // node: { // fs: "empty", // net: "empty", // tls: "empty" // }, target: "node" } 

当我编译代码时,我得到这些警告:

 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 ./~/bcrypt/~/bindings/bindings.js Critical dependencies: 76:22-40 the request of a dependency is an expression 76:43-53 the request of a dependency is an expression @ ./~/bcrypt/~/bindings/bindings.js 76:22-40 76:43-53 WARNING in ./~/mongoose/~/bson/lib/bson/index.js Critical dependencies: 20:16-29 the request of a dependency is an expression 44:18-31 the request of a dependency is an expression 71:19-32 the request of a dependency is an expression @ ./~/mongoose/~/bson/lib/bson/index.js 20:16-29 44:18-31 71:19-32 WARNING in ./~/mongodb/~/es6-promise/dist/es6-promise.js Module not found: Error: Cannot resolve module 'vertx' in C:\bifrostApp\node_modules\mongodb\node_modules\es6-promise\dist @ ./~/mongodb/~/es6-promise/dist/es6-promise.js 132:20-30 WARNING in ./~/mongodb/~/mongodb-core/~/bson/lib/bson/index.js Critical dependencies: 20:16-29 the request of a dependency is an expression 44:18-31 the request of a dependency is an expression 71:19-32 the request of a dependency is an expression @ ./~/mongodb/~/mongodb-core/~/bson/lib/bson/index.js 20:16-29 44:18-31 71:19-32 

谷歌search后,我发现这个https://github.com/webpack/webpack/issues/196这似乎说它不是一个交易断路器。 仍然不完全确定是否。 该脚本编译没有错误,只有这些警告。 生成其中一个警告的代码是:

 /*! * ignore */ var driver; if (typeof window === 'undefined') { driver = require(global.MONGOOSE_DRIVER_PATH || './node-mongodb-native'); } else { driver = require('./browser'); } /*! * ignore */ module.exports = driver; 

当我运行节点的脚本,我得到这个错误: Error: Cannot find module './node-mongodb-native'. at C:\bifrostApp\app.js:2165:42 at webpackContextResolve (C:\bifrostApp\app.js:2165:90) at webpackContext (C:\bifrostApp\app.js:2162:30) at Object.map../SPEC.md (C:\bifrostApp\app.js:2120:35) at __webpack_require__ (C:\bifrostApp\app.js:20:30) at Object.<anonymous> (C:\bifrostApp\app.js:832:17) at __webpack_require__ (C:\bifrostApp\app.js:20:30) at Object.<anonymous> (C:\bifrostApp\app.js:125:15) at __webpack_require__ (C:\bifrostApp\app.js:20:30) at Object.<anonymous> (C:\bifrostApp\app.js:112:19) Error: Cannot find module './node-mongodb-native'. at C:\bifrostApp\app.js:2165:42 at webpackContextResolve (C:\bifrostApp\app.js:2165:90) at webpackContext (C:\bifrostApp\app.js:2162:30) at Object.map../SPEC.md (C:\bifrostApp\app.js:2120:35) at __webpack_require__ (C:\bifrostApp\app.js:20:30) at Object.<anonymous> (C:\bifrostApp\app.js:832:17) at __webpack_require__ (C:\bifrostApp\app.js:20:30) at Object.<anonymous> (C:\bifrostApp\app.js:125:15) at __webpack_require__ (C:\bifrostApp\app.js:20:30) at Object.<anonymous> (C:\bifrostApp\app.js:112:19)

./node-mongodb-native是一个目录,错误来自webpackContextResolve(req) ,上面的path是req

 var map = { "./SPEC.md": 6, "./browser/ReadPreference": 7, "./browser/ReadPreference.js": 7, "./browser/binary": 8, "./browser/binary.js": 8, "./browser/index": 31, "./browser/index.js": 31, "./browser/objectid": 32, "./browser/objectid.js": 32, "./index": 4, "./index.js": 4, "./node-mongodb-native/ReadPreference": 33, "./node-mongodb-native/ReadPreference.js": 33, "./node-mongodb-native/binary": 134, "./node-mongodb-native/binary.js": 134, "./node-mongodb-native/collection": 135, "./node-mongodb-native/collection.js": 135, "./node-mongodb-native/connection": 225, "./node-mongodb-native/connection.js": 225, "./node-mongodb-native/index": 231, "./node-mongodb-native/index.js": 231, "./node-mongodb-native/objectid": 232, "./node-mongodb-native/objectid.js": 232 }; function webpackContext(req) { return __webpack_require__(webpackContextResolve(req)); }; function webpackContextResolve(req) { return map[req] || (function() { throw new Error("Cannot find module '" + req + "'.") }()); }; 

./node-mongodb-native文件夹的path将不在那里,这是有道理的,因为map的文件稍后将用.call来执行。 我的问题是,为什么该文件夹结束了一个文件path列表? 我该如何解决这个问题? 我想它的一个webpack的问题,只是不太确定该怎么做。 任何帮助将不胜感激。

我试图运行我的脚本与node 。 用babel-node运行它修复它。