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的文件名微小的差異。 –