我正在测试我的新设置,为此我正在编译服务器端脚本,如下所示:
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,具有以下配置:
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
谷歌搜索后,我发现了这一点 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)
./ node-mongodb-native是一个目录,错误来自webpackContextResolve(req)
,上述路径为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文件夹的路径将不存在,这是有道理的,因为map
中的文件将在稍后使用.call执行。我的问题是,为什么该文件夹最终会有一个文件路径列表?我该怎么做才能解决这个问题?我认为它是一个webpack问题,只是不太确定如何处理它。任何帮助将不胜感激。
答案 0 :(得分:4)
我试图用node
运行我的脚本。通过babel-node
运行它来修复它。
答案 1 :(得分:0)
这是一个webpack警告消息。 请查看此http://webpack.github.io/docs/context.html#critical-dependencies以找到答案