Node-redis: Error while building with webpack

Created on 28 Jul 2015  ·  8Comments  ·  Source: NodeRedis/node-redis

I am getting the following error when building with webpack:

ERROR in ./~/redis/lib/parser/hiredis.js
Module not found: Error: Cannot resolve module 'hiredis' in C:\NodeServer\AppInTheWild\node_modules\redis\lib\parser
 @ ./~/redis/lib/parser/hiredis.js 3:14-32

I do not want to install hiredis as a depency. What solution do I have?

question

Most helpful comment

Had the same error, and got it working by borrowing the solution from here.

So the relevant snippet in webpack.config.js looks like this:

resolve: {
  alias: {
    'hiredis': path.join(__dirname, 'aliases/hiredis.js')
  }
}

And also I created the file aliases/hiredis.js that has the following content:

export default null

All 8 comments

Seems like webpack isn't detecting that hiredis is an optional dependency of node_redis.

What is your webpack config like? I found an interesting article showing how you should only package your own code and leave anything in node_modules as is. This way you are not pulling in 3rd party modules and packaging them into your final build file. Unless, of course, you are trying to do this.

http://jlongster.com/Backend-Apps-with-Webpack--Part-I

Closing this as there was no further response and it's not an issue with node-redis

I have the same issue; webpack only seems to fail with node_redis (i'm using webpack successfully to package the rest of my backend using webpack-node-externals to skip node_module deps).

~~~~
ERROR in ./~/redis-commands/index.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./commands in demo/node_modules/redis-commands
@ ./~/redis-commands/index.js 3:15-36

ERROR in ./~/redis-parser/lib/hiredis.js
Module not found: Error: Cannot resolve module 'hiredis' in demo/node_modules/redis-parser/lib
@ ./~/redis-parser/lib/hiredis.js 3:14-32
~~~~

@blainsmith my config here:

~~~~
const nodeExternals = require('webpack-node-externals');
module.exports = {
target: 'node',

externals: [nodeExternals()],

resolve: {
extensions: ['', '.js'],
modulesDirectories: [
'node_modules'
]
},

module: {
resolveLoader: {
root: path.join(__dirname, 'node_modules')
},
loaders: [
{
test: /.json$/,
loader: 'json-loader'
},
{
test: /.js$/,
exclude: [/node_modules/],
loader: 'babel-loader'
},
]
},
});
~~~~

Experiencing the same thing here. Other dependencies are resolved.

The dev script works, the build:dev script fails. Same webpack.config.js.

Scripts

"dev": "DEBUG=* && webpack-dev-server --bail --config webpack.config.js --host 0.0.0.0",
"build:dev": "webpack --config webpack.config.js ",

Deps

"botkit-storage-redis": "1.1.0",

Build error

ERROR in ./~/redis-parser/lib/hiredis.js
Module not found: Error: Can't resolve 'hiredis' in '/path/to/node_modules/redis-parser/lib'
 @ ./~/redis-parser/lib/hiredis.js 3:14-32
 @ ./~/redis-parser/lib/parser.js
 @ ./~/redis-parser/index.js
 @ ./~/redis/index.js
 @ ./~/botkit-storage-redis/src/index.js
 @ ./~/botkit-storage-redis/index.js
 @ ./src/index.js

Had the same error, and got it working by borrowing the solution from here.

So the relevant snippet in webpack.config.js looks like this:

resolve: {
  alias: {
    'hiredis': path.join(__dirname, 'aliases/hiredis.js')
  }
}

And also I created the file aliases/hiredis.js that has the following content:

export default null
yarn add hiredis
npm i --save hiredis

Simple solution without a hack

Seeing as hiredis is an optional dependency, and I don't want to install unnecessary dependencies, but I also don't want to hack in aliases, the simplest solution is to utilize webpack.IgnorePlugin().

Add to webpack.config.js

plugins: [
    new webpack.IgnorePlugin(/^hiredis$/)
  ],
Was this page helpful?
0 / 5 - 0 ratings

Related issues

michaelwittig picture michaelwittig  ·  3Comments

dotSlashLu picture dotSlashLu  ·  5Comments

adamgajzlerowicz picture adamgajzlerowicz  ·  4Comments

twappworld picture twappworld  ·  7Comments

Alchemystic picture Alchemystic  ·  6Comments