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

cannot include dependencies not required by bundle (knex pg). #217

jonni-larjomaa opened this Issue Sep 8, 2017 · 3 comments


None yet
2 participants
Copy link

jonni-larjomaa commented Sep 8, 2017


I'm using knex and bookshelf with pg-library, the problem is that the pg library does not get bundled in to node_modules directory because it is not required in the files that get bundled (but is required by knex on runtime). This causes AWS Lambda to throw following errors.

2017-09-08T07:28:40.829Z 52dbac4f-9467-11e7-af3a-fdbf9a737897 Knex: run
$ npm install pg --save
Error: Cannot find module 'pg'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Client_PG._driver (/var/task/node_modules/knex/lib/dialects/postgres/index.js:91:12)
at Client_PG.initializeDriver (/var/task/node_modules/knex/lib/client.js:219:26)
at Client_PG.Client (/var/task/node_modules/knex/lib/client.js:113:10)
at new Client_PG (/var/task/node_modules/knex/lib/dialects/postgres/index.js:56:20)
at Knex (/var/task/node_modules/knex/lib/index.js:60:34)
at (/var/task/index.js:102:35)
at webpack_require (/var/task/index.js:20:30)
at Object. (/var/task/index.js:79:17)
at webpack_require (/var/task/index.js:20:30)
at Object. (/var/task/index.js:270:12)
at webpack_require (/var/task/index.js:20:30)
at Object. (/var/task/index.js:217:15)

Probably the cause is that this is not direct depency but resolved one during runtime which is then not resolved by webpack during bundling. I would appreciate a lot if this could work, although i could also probably just:

var dump = require("pg");

in order to get it bundled for now


This comment has been minimized.

Copy link

jonni-larjomaa commented Sep 8, 2017

And yes the pg-library can be found from package.json and also from node_modules folder


This comment has been minimized.

Copy link

HyperBrain commented Sep 8, 2017

Hi @jonni-larjomaa . Thanks for bringing this up 👍 .

Yes, currently it is indeed so, that Webpack optimizes the package and reports the needed dependencies to the plugin, that in turn uses them to build a working package. As long as webpack does not know that a specific module is needed, although it is not referenced, it will not be packaged.

Good to know that it works with your workaround.

This is a missing feature that could be implemented quite easily. My proposal would be that we just use the custom.webpackIncludeModules flag which currently only can be true to control whether modules are packaged or not.
The flag can be extended to be optionally an array of modules that are forced to be packaged, even if they are not referenced after the webpack compile anymore.

In your case you would then specify:

    - pg

This will then do a forced package of the pg module.


This comment has been minimized.

Copy link

HyperBrain commented Sep 22, 2017

Released with 3.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment