0
我正在使用Webpack在浏览器中使用require模块;然而,我发现了以下错误:与Mongoose一起使用Webpack - mongoose.model不是函数
Uncaught TypeError: mongoose.model is not a function
at Object.<anonymous> (bundle.js:44338)
at __webpack_require__ (bundle.js:20)
at Object.<anonymous> (bundle.js:48)
at Object.<anonymous> (bundle.js:68)
at __webpack_require__ (bundle.js:20)
at bundle.js:40
at bundle.js:43
我知道猫鼬根据http://mongoosejs.com/docs/browser.html和我甚至包括脚本标签建议,仍然收到错误在浏览器中的一些限制。
我还远销我用猫鼬模块正确:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ProductSchema = new Schema({
imageURL: String,
productName: String,
productType: String,
price: String
}, {collection: 'products'});
module.exports = mongoose.model('products', ProductSchema);
我webpack.config.js被正确的配置以及
var webpack = require('webpack');
var path = require('path');
var fs = require('fs');
var request = require('request');
var CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
module.exports = {
entry: "./main.js",
output: {
path: __dirname,
filename: "bundle.js"
},
module: {
loaders: [
{ test: /\.json$/, loader: 'json-loader' }
]
},
resolve: {
extensions: ['', '.webpack.js', '.web.js', '.js', '.json']
},
node: {
console: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty'
}
}
为什么会发生这种情况?如何解决这个问题?
只是想我会提到这发生在我身上时,我的角2单元测试意外进口了错误的服务由于服务器的账户服务和角度的account.service的文件名微小的差异。 –