MongoDB throwing error Module not found: 'module' MongoDB throwing error Module not found: 'module' mongoose mongoose

MongoDB throwing error Module not found: 'module'


This error is because you're trying to use mongodb from browser, as create-react-app is a front-end app.You should use a back-end server and use mongodb from there.

You can check out this this full-stack repo having a nodejs server with create-react-app front-end.https://github.com/fullstackreact/food-lookup-demo


That is because Webpack can’t statically analyze if (typeof window === 'undefined') in mongoose/lib/drivers/index.js

Here is the solution:

webpackConfig.plugins = [...,new webpack.DefinePlugin({'typeof window': "\"object\""}),...]Also, if you get error messages regarding mongoose, check out below configurations.npm install node-loader --save-devnpm install require_optional --save-devnpm install module --save-devwebpack.config.jsconst webpackConfig = {name : 'client',target : 'web',devtool : config.compiler_devtool,resolve : {root : paths.client(),extensions : ['', '.js', '.jsx', '.json', '.coffee', '.node']},node: {fs: 'empty',net: 'empty',tls: 'empty'},module : {}}// ------------------------------------// Loaders// ------------------------------------// JavaScript / JSONwebpackConfig.module.loaders = [{test : /\.(js|jsx)$/,exclude : /node_modules\/(?!(lodash-es)\/).*/,loader : 'babel',query : config.compiler_babel}, {test : /\.json$/,loader : 'json'}, {test: /\.coffee$/,loader: 'coffee-loader',exclude: /node_modules|lib/}, {test: /\.node$/,loader: 'node-loader'}]