-
-
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 using Schema in browser: __webpack_require__(...) is not a function #5842
Comments
I don't know unfortunately, we don't really have good support for webpack ATM. @varunjayaraman is the resident expert on the interplay with mongoose and webpack. |
Yeah that makes sense, as mongoose is primarily backend. Hopefully it's easy to workout because your decision to support schema validation in the browser is great for DRY in isomorphic js apps, and most using React on the front-end use Webpack. |
hey @raythree sorry ive been on vacation, anyway this is a problem that unfortunately creeps up from time to time with mongoose. I've been able to reproduce your issue with a simple repro script webpack.config.jsconst path = require('path');
const webpack = require('webpack');
module.exports = {
entry: './src/client.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
plugins: [
new webpack.DefinePlugin({ 'typeof window': '\"object\"' })
]
} src/client.jsimport mongoose from 'mongoose'; index.html<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<div>hi</div>
<script src="dist/bundle.js"></script>
</body>
</html> package.json{
"name": "gh-5842",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack"
},
"author": "",
"license": "ISC",
"dependencies": {
"mongoose": "^4.13.6",
"webpack": "^3.10.0"
}
} I'll need to do some more research, but I do get the same error message as you in the console when i open up |
We have a react-slingshot project that uses Mongoose.schema in the browser for form validation. We have this in our webpack config as per the docs:
Everything worked fine when we started the project using mongoose
4.11.5
. After upgrading to mongoose4.13.4
the project no longer runs in dev mode (npm start) generating this error:From inside one of the mongoose files. It occurs on the first line shown below when requiring the Document:
Initially we didn't lock down the version of mongoose inside package.json and this started happening after version 4.11.5. I tried with the latest and it still persists. Locking the mongoose version at 4.11.5 works fine. Any ideas what changes would have caused this?
Thanks!
The text was updated successfully, but these errors were encountered: