Skip to content
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

Uncaught TypeError: Cannot read property 'prototype' of undefined #7173

Closed
misland opened this issue Oct 23, 2018 · 11 comments
Closed

Uncaught TypeError: Cannot read property 'prototype' of undefined #7173

misland opened this issue Oct 23, 2018 · 11 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.

Comments

@misland
Copy link

misland commented Oct 23, 2018

What is the current behavior?
I just import mongoose in a project that initialized by vue-cli 2.0,when I run the project ,an error thrown as the title said,can anyone explain why?thanks!!
here is the detail of error:
Uncaught TypeError: Cannot read property 'prototype' of undefined
at eval (webpack-internal:///./node_modules/mongoose/lib/types/buffer.js:184)
at Array.forEach ()
at Object.eval (webpack-internal:///./node_modules/mongoose/lib/types/buffer.js:183)
at eval (webpack-internal:///./node_modules/mongoose/lib/types/buffer.js:306)
at Object../node_modules/mongoose/lib/types/buffer.js (app.bundle.js:2554)
at webpack_require (app.bundle.js:679)
at fn (app.bundle.js:89)
at Object.eval (webpack-internal:///./node_modules/mongoose/lib/schema/buffer.js:10)
at eval (webpack-internal:///./node_modules/mongoose/lib/schema/buffer.js:225)
at Object../node_modules/mongoose/lib/schema/buffer.js (app.bundle.js:2386)
at webpack_require (app.bundle.js:679)
at fn (app.bundle.js:89)
at eval (webpack-internal:///./node_modules/mongoose/lib/schema/array.js:19)
at Object../node_modules/mongoose/lib/schema/array.js (app.bundle.js:2370)
at webpack_require (app.bundle.js:679)
at fn (app.bundle.js:89)

Please mention your node.js, mongoose and MongoDB version.
Node.js 8.12
mongoose 5.3.5
MongoDB 4.0.3

@nikdunn
Copy link

nikdunn commented Oct 24, 2018

The fix for this issue: #7102 seems to have been what introduces this bug. There is no Buffer property on global when NodeBuffer gets created.

@misland
Copy link
Author

misland commented Oct 25, 2018

The fix for this issue: #7102 seems to have been what introduces this bug. There is no Buffer property on global when NodeBuffer gets created.

thanks my friend

@misland misland closed this as completed Oct 25, 2018
@nikdunn
Copy link

nikdunn commented Oct 25, 2018

Why did you close this Issue? It's not fixed. This should be an open issue.
@misland Can you reopen the issue?
@vkarpov15 I wanted to bring this to your attention. Thanks.

@lineus
Copy link
Collaborator

lineus commented Oct 25, 2018

@nikdunn does 5.3.6 fix the issue for you?

@lineus lineus reopened this Oct 25, 2018
@nikdunn
Copy link

nikdunn commented Oct 25, 2018

No, @lineus , 5.3.6 is where the issue is introduced. I was using 5.3.4 and then an npm install bumped me to 5.3.6 where I started experiencing the issue.

@lineus
Copy link
Collaborator

lineus commented Oct 26, 2018

this issue was introduced in @5.3.5

I am able to replicate this using a new [email protected] webpack app and just adding the mongoose import statement import mongoose from 'mongoose/browser'; on [email protected].{5,6}. On [email protected] it works without issue.

I am also able to repro this using create-react-app and [email protected].{5,6}.

@lineus lineus added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label Oct 26, 2018
@misland
Copy link
Author

misland commented Oct 26, 2018

@nikdunn sorry that I didn't quite familar with github issues,@lineus has opened this already

@vkarpov15
Copy link
Collaborator

Thanks for helping us find this issue. We started using the core node buffer for a couple use cases to work around a bug in safe-buffer (feross/safe-buffer#23) .

vkarpov15 added a commit that referenced this issue Oct 26, 2018
fixes #7173 fallback to safe-buffer in the browser
@delucca
Copy link

delucca commented Jan 25, 2019

I´m getting the same error on a Jest test suite:

    TypeError: Cannot read property 'prototype' of undefined

      at Object.<anonymous> (node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:160:28)
      at Object.<anonymous> (node_modules/mongoose/lib/drivers/node-mongodb-native/index.js:8:22)
      at Object.<anonymous> (node_modules/mongoose/lib/index.js:10:27)

Any toughts on how to fix it?

@vkarpov15
Copy link
Collaborator

@odelucca can you provide code samples? The original issue had nothing to do with jest and jest has a lot of issues. If you're going to use jest, make sure you read this doc: https://mongoosejs.com/docs/jest.html

@delucca
Copy link

delucca commented Jan 30, 2019

@vkarpov15 thanks for the reply. I found out that the issue wasnt with mongoose :)

Thanks!

@Automattic Automattic locked as resolved and limited conversation to collaborators Feb 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

5 participants