-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
fix: fix browser build for Webpack 5 #11717
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks! 👍
lib/helpers/isAsyncFunction.js
Outdated
// for a simple check. | ||
try { | ||
asyncFunctionPrototype = Object.getPrototypeOf(async function() {}); | ||
} catch (err) {} | ||
|
||
module.exports = function isAsyncFunction(v) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could avoid a potential performance penalty by checking the value of asyncFunctionPrototype only once.
module.exports = asyncFunctionPrototype !== null
? function isAsyncFunction(v) {
return (
typeof v === 'function' &&
Object.getPrototypeOf(v) === asyncFunctionPrototype
);
}
: function () { return false; };
What is the actual purpose of the browser build? |
@Uzlopak the browser build is supposed to let you run basic schema validation in the browser. The syntax is slightly different: there's no models, you need to define a schema when you create a document. But you can at least define and use Mongoose schemas in the browser. For example: <html>
<head>
<script src="/dist/browser.umd.js"></script>
<script>
const schema = new mongoose.Schema({
name: { type: String, required: true },
quest: { type: String, match: /Holy Grail/i, required: true },
favoriteColor: { type: String, enum: ['Red', 'Blue'], required: true }
});
doc = new mongoose.Document({
name: 'Sir Lancelot of Camelot',
quest: 'To seek the Holy Grail',
favoriteColor: 'Blue'
}, schema);
console.log(doc.validateSync()); // null
doc.set({
name: 'Sir Galahad of Camelot',
quest: 'To seek the Holy Grail',
favoriteColor: 'Yellow'
});
console.log(doc.validateSync()); // ValidationError
</script>
</head>
<body></body>
</html> |
I'm genuinely curious if anyone out there is relying on that. |
Re: #11584
Summary
With #11584, there were a few issues that popped up in the browser build:
Buffer
process
isAsyncFunction()
Examples