-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error importing mongoose on clientside using es6 import, webpack, and create-react-app #5610
Comments
Also filed with create-react-app facebook/create-react-app#3050 (comment) comment by gaearon on that site: As a temporary fix, you can always use mongoose as a <script> tag by putting its JS file into the public/ folder, adding a <script> to index.html, and then using it via window.mongoose." |
This seems like a weird bug. If you put a on line 98: /*!
* Inherit from the NodeJS document
*/
console.log(NodeJSDocument.prototype); // undefined
Document.prototype = Object.create(NodeJSDocument.prototype);
Document.prototype.constructor = Document; |
Thanks for taking a look at this today. Since this is in the browser, there should be no nodeJSDocument, right? |
maybe its a bit of a misnomer but if you look at line 5 of
|
So I've been doing some research and I think I'm onto something. I think something recently in the way mongoose is imported on the client has broken the way webpack resolves dependencies bc the native bson module is now getting imported in mongoose somehow. I'll report back when I've confirmed, just using this more as a way to document my investigation |
@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 |
Nope no progress. |
Please let us know for any updates... |
Happens for me without using create-react-app |
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
The text was updated successfully, but these errors were encountered: