4.11.9
Do you want to request a feature or report a bug?
Report a Bug
What is the current behavior?
Error when loading page that imports mongoose on the client side when using webpack through create-react-app.
This line of code:
new webpack.DefinePlugin({ 'typeof window': '"object"' })
from
http://mongoosejs.com/docs/browser.html
does not appear to fix it.
The error:
脳 TypeError: Object prototype may only be an Object or null: undefined
(anonymous function)
node_modules/mongoose/lib/browserDocument.js:99
If the current behavior is a bug, please provide the steps to reproduce.
npm install -g create-react-app
create-react-app foo
cd foo
npm install --save mongoose
edit App.js to add to the first line:
import mongoose from "mongoose";
npm start // or yarn start if using yarn
What is the expected behavior?
App loads without error.
Please mention your node.js, mongoose and MongoDB version.
node.js 7.2.0
mongoose 4.11.9
MongoDB ... irrelevant, this is client side
Also filed with create-react-app
https://github.com/facebookincubator/create-react-app/issues/3050#event-1232121738
comment by gaearon on that site:
"Please file an issue with mongoose. The requirement to add a plugin to webpack configuration to consume a library is not great and puts a complexity tax on the ecosystem. I believe it is completely avoidable on the mongoose side if they prioritize fixing it.
As a temporary fix, you can always use mongoose as a
@varunjayaraman yeah that's expected behavior AFAIK. We include bson to get ObjectIds without having to go through the driver, because importing the driver itself made browserify blow up.
what's confusing to me is that it only fails with create-react-app
Yeah I honestly have no idea and don't want to spend more time trying to support create-react-app. Its a very niche edge case for mongoose.
Same error here when including a second reference to a Mongoose schema. Any news on a fix?
browserDocument.js:99 Uncaught TypeError: Object prototype may only be an Object or null: undefined
at Function.create (
at Object.
at Object.
at __webpack_require__ (bootstrap 016093d5014cbaec899c:555)
at fn (bootstrap 016093d5014cbaec899c:86)
at Object.
at __webpack_require__ (bootstrap 016093d5014cbaec899c:555)
at fn (bootstrap 016093d5014cbaec899c:86)
at Object.
at __webpack_require__ (bootstrap 016093d5014cbaec899c:555)
Nope no progress.
Please let us know for any updates...
Happens for me without using create-react-app
Most helpful comment
Please let us know for any updates...