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
WebPack related error: LevelUp package.json produces errors #3319
Comments
@svnlto has a recent commit that helped get this working in webpack, have you been trying with master or the last release? Since we use the leveldb browser versions (leveljs etc), not sure we can straight use |
Here's what needs to be done (in webpack's config), to get it working with pouchdb: module: {
loaders: [{
test: /\.json$/,
loader: 'json'
},
{
test: /\.j(s|sx)$/,
loader: 'react-hot!es6-loader!jsx-loader?harmony',
exclude: /node_modules/
}],
noParse: /lie.js/
}, also, you should work from master, it contains the additional fix.
perhaps that might be something we'd want to look at as well. |
Awesome! I was on master already, but that config has the levelup problem fixed. Thanks @svnlto. |
@daleharvey I've picked this up again with more recent versions of "browser": {
"levelup": false,
"leveldown": false
} |
I had to remove WARNING in ./~/pouchdb/~/lie/~/immediate/dist/immediate.js
Critical dependencies:
1:440-447 This seem to be a pre-built javascript file. Even while this is possible, it's not recommended. Try to require to orginal source to get better results.
@ ./~/pouchdb/~/lie/~/immediate/dist/immediate.js 1:440-447
WARNING in ./~/pouchdb-authentication/~/lie/~/immediate/dist/immediate.js
Critical dependencies:
1:440-447 This seem to be a pre-built javascript file. Even while this is possible, it's not recommended. Try to require to orginal source to get better results.
@ ./~/pouchdb-authentication/~/lie/~/immediate/dist/immediate.js 1:440-447 |
Can you provide a PR? I'm not too familiar with webpack, but we definitely want it to at least work in webpack. As for the warnings, they don't seem too severe. :) |
Trying to solve this for myself now. Any more tips @svnlto ? with "browser": { in pouchDB package.json
|
I should have a PR ready in the next couple of days. As to the warning, try the ...
noParse: /lie\.js$/
... |
great that removes the warnings, thanks! |
Those steps get it working for me, but it still seems to be including a ton of stuff it doesn't need. var PouchDb = require('pouchdb/dist/pouchdb'); generates the same warning @timcash mentioned above, but shaves ~300K off the unminified bundle for me. |
I created a simple repo to demonstrate: https://github.com/MattKunze/pouchdb-webpack
normal.js includes PouchDB as described in this thread, dist.js requires the dist version. You can see the file size difference above. So it seems like there is a workable solution, but it would be nice to have it work as a native require so any other shared dependencies aren't duplicated. |
Webpack does not like that `leveldown` is trying to use `fs`. We can harmlessly set it to `false` in the package.json. For `levelup`, the issue is that it's trying to directly load its own package.json file, which is apparently a big contentious issue in Webpack, and the standard solution is that app devs add their own json loader, which is what Webpack devs themselves advocate (see [here](webpack/webpack#378 (comment))) and [here](http://mattdesl.svbtle.com/browserify-vs-webpack)). We can add a note about this Webpack config fix to our own wiki, or we can just trust that Webpack-using devs will find it themselves after 5 minutes of googling the JSON issue (I found it in about as much time). In any case, the bare minimum we need to do is set `leveldown` to `false`.
Webpack does not like that `leveldown` is trying to use `fs`. We can harmlessly set it to `false` in the package.json. For `levelup`, the issue is that it's trying to directly load its own package.json file, which is apparently a big contentious issue in Webpack, and the standard solution is that app devs add their own json loader, which is what Webpack devs themselves advocate (see [here](webpack/webpack#378 (comment))) and [here](http://mattdesl.svbtle.com/browserify-vs-webpack)). We can add a note about this Webpack config fix to our own wiki, or we can just trust that Webpack-using devs will find it themselves after 5 minutes of googling the JSON issue (I found it in about as much time). In any case, the bare minimum we need to do is set `leveldown` to `false`.
Webpack does not like that `leveldown` is trying to use `fs`. We can harmlessly set it to `false` in the package.json. For `levelup`, the issue is that it's trying to directly load its own package.json file, which is apparently a big contentious issue in Webpack, and the standard solution is that app devs add their own json loader, which is what Webpack devs themselves advocate (see [here](webpack/webpack#378 (comment))) and [here](http://mattdesl.svbtle.com/browserify-vs-webpack)). We can add a note about this Webpack config fix to our own wiki, or we can just trust that Webpack-using devs will find it themselves after 5 minutes of googling the JSON issue (I found it in about as much time). In any case, the bare minimum we need to do is set `leveldown` to `false`.
So this issue is fixed; I can For the JSON problem, the issue is that levelup is trying to directly load |
Confirmed that requiring pouchdb directly works now without any workarounds, but I'm still seeing the file size differences between requiring lib/index.js vs the dist bundle. The overhead is ~400kB (~150kB minified), so it's a pretty big difference |
Can you debug Webpack to see what it's including? Browserify has disc, but I'm not sure if Webpack has anything similar. |
Also the reason the dist bundle is so small is because we spent a lot of time optimizing our Browserify build to remove stuff we don't need. Someone now needs to go through the same dance for Webpack. :) |
Was there a PR where you optimized it for browserify? That might be a good place to start. webpack lists the modules it's including, so it's easy to know what is being included. I'll see if there's a verbose option to browserify to get similar results that can be compared. |
Can't think of a particular one; there were lots of little ones that built up over time. Basically all of those optimizations are expressed in this code. Things like disabling Other things are more subtle to browserify, such as the fact that we sub out |
Yeh the |
For posterity, webpack users, do: module: {
loaders: [
// https://github.com/pouchdb/pouchdb/issues/3319
{
test: /\.json$/,
loader: "json-loader"
}
]
} |
@dashed Could you add this to the "common errors" page? Might be really helpful to people. |
Good call. I amended the errors page. |
If we config webpack on this repo will it solve that problem? |
@NickColley No, webpack specifically says that this kind of stuff is supposed to be solved by the end-user. |
When packaging PouchDB in an app with WebPack, the following error gets output. The current PouchDB npm release doesn't build because of a bug recently fixed (see #3287). The current github master allows it to proceed but it then hits the error below.
Unless I'm mistaken LevelUP shouldn't be required in the client? Can it be left out of the package altogether in a similar manor to the fix for #3287 ?
Is it ok to just add
levelup: false
to thebrowser
section ofpackage.json
or should it be replaced with a browser compatible module?The text was updated successfully, but these errors were encountered: