我具有用于连接到mongo的功能connect()
:
//index.js
const mongoose = require('mongoose');
const connect = () => {
mongoose.connect(databaseUrl, options).catch(error => console.log(error));
mongoose.connection
.once('open', () => console.log('Success: connected to ' + databaseUrl))
.on('error', (error) => {
console.warn('Error : ',error);
});
};
connect();
如果我什至尝试使用最小的Webpack配置,它看起来可能像这样:
//webpack.config.js
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
entry: './index.js',
plugins: [new HtmlWebpackPlugin]
};
我得到了错误:
Uncaught (in promise) TypeError: mongoose.connect is not a function
我也有nodemon在应用程序中。当我使用它时,脚本将成功完成-Success: connected to databaseUrl
我到底在做什么错? Webpack中的哪些程序可以打破这一点?