Open richburdon opened 7 years ago
I have a simple webpack configuration for server side bundling and faced an issue exactly like yours. Adding nodeExternals() plugin solved the problem in my case. Here is related code in my webpack configuration:
{
...
externals: [nodeExternals()],
target: 'node',
...
}
It just skips all packages inside node_modules directory while bundling.
But why do you skip all packages inside node_modules while bundling? This looks like a workaround and not a proper fix?
Yes, it is not a proper fix but we don't need bundling in server side anyway. Not just packages inside node_modules folder, any package or module we import our code may not have to be bundled in server side since node supports es6 modules. Maybe redis lib maintainer clarify this problem better.
@sprinklr-gurgaon Because most node-only libraries do lazy require
ing using require
(and not require.ensure
, which is not part of node
), which causes webpack to fail.
I use nodeExternals a lot to build server-side modules, but I get this error for any project that depends (indirectly) on redis (all other modules -- 1000s of them -- work fine).
In this case, my import of
bull
causes problems, through its dependency onioredis
(similar issues https://github.com/webpack/webpack-dev-server/issues/227 and https://github.com/NodeRedis/node_redis/issues/790)Solution may relate to https://github.com/liady/webpack-node-externals/issues/29
The workaround is to add to "optionalDependencies" all modules that my other sub projects depend upon and set
modulesFromFile
but this is messy.