Node-redis: hiredis is not being installed

Created on 11 Jul 2017  路  13Comments  路  Source: NodeRedis/node-redis

  • Version: 2.7.1
  • Platform: Node.js 8.1.3 / macOS 10.12.5
  • Description: After running yarn or npm install on the project and while generating a webpack build I got this error
ERROR in ./node_modules/redis-parser/lib/hiredis.js
Module not found: Error: Can't resolve 'hiredis' in
error Command failed with exit code 2.

The webpack config is the following:

var path = require('path')

module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist')
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: ['babel-loader']
      }
    ]
  },
  target: 'node'
}

package.json

{
  "version": "1.0.0",
  "main": "src/index.js",
  "license": "MIT",
  "dependencies": {
    "dotenv": "^4.0.0",
    "koa": "^2.3.0",
    "koa-bodyparser": "^4.2.0",
    "koa-router": "^7.2.1",
    "node-fetch": "^1.7.1",
    "redis": "^2.7.1"
  },
  "devDependencies": {
    "babel-cli": "^6.24.1",
    "babel-loader": "^7.1.1",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-plugin-transform-object-rest-spread": "^6.23.0",
    "babel-preset-env": "^1.5.2",
    "webpack": "^3.0.0"
  },
  "scripts": {
    "start": "node dist/bundle",
    "build": "webpack"
  },
  "babel": {
    "presets": [
      [
        "env",
        {
          "targets": {
            "node": "current"
          }
        }
      ]
    ],
    "plugins": [
      "transform-object-rest-spread",
      "transform-class-properties"
    ]
  }
}
invalid

Most helpful comment

Actually, that's not an issue with Webpack. That's an issue with how redis-parser used hiredis. This issue can be solved by upgrading to redis-parser 3.0, which solves exactly this issue.

All 13 comments

That must be related with webpack. I was solved this issue by using nodeExternals plugin in webpack config:

const nodeExternals = require('webpack-node-externals')

module.exports = {
  ...
  externals: [nodeExternals()],
  target: 'node'
}

nodeExternals skips any module in node_modules folder at server side bundling.

This is an issue with webpack.

Actually, that's not an issue with Webpack. That's an issue with how redis-parser used hiredis. This issue can be solved by upgrading to redis-parser 3.0, which solves exactly this issue.

@guidobouman how can we use redis-parser 3.0 without forking node_redis and upgrading that single dependency? I've been looking for a solution to this problem for weeks with no success.

@guidobouman any valid JS code should be fine for Webpack. That does not seem to be the case and that's sad. That aside: I very much wonder why someone would want to use Webpack on redis. Minifying server side code is a pretty bad idea.

@peterschussheim I do not have a lot of capacity to work on node_redis at the moment and that's pretty sad. Upgrading only the redis-parser would be a semver-major bump though.

@BridgeAR See https://github.com/NodeRedis/node-redis-parser/pull/36

The missing reference was the underlying issue with Webpack. Removing hiredis completely also fixed that bug as "collateral damage".

As to why one would run webpack on server related code: serverless environments might run old versions of Node while someone wants to be able to use modern syntax like imports. (https://github.com/serverless-heaven/serverless-webpack)

@peterschussheim I see another option aside from bumping the version for redis-parser in node-redis: install hiredis yourself. Even though you're probably not using hiredis, redis-parser does expect it being present.

Actually, @BridgeAR: This could go as a patch version bump as it's a bugfix. But yes, it drops Node versions below 4, even though they have been EOL for quite some time.

@guidobouman Thank you very much for that suggestion. Although it is a 'hack', i'll accept it since I can't waste more time than I already have due to this problem.

Perhaps this is a good opportunity for myself or others in the community to release a 'modern' version (very, very sad that we are holding off from changes like this because of node 4 support).

馃憥

Can someone please explain how to fix this issue? I don't understand why I still need to add hiredis as a direct dependency. Others suggest to simply not use hiredis, so how should I accomplish that?
Documentation says that the default parser is not hiredis. I'm using latest version and hiredis is still being required. Webpack is failing miserably when bundling for AWS lambda runtime.

After all of adjustments(change to target: 'node' and additionally install 'hiredis'), still there seems be
a problem in bundling. "Uncaught ReferenceError: require is not defined" shows up when I try to use Redis with Webpack.

This issue is still relevant, as hiredis is abonded and failed to install in Node 12, redis-parser remove it on v3.0.0 but this package still using v2.6.0.

Also seeing this when trying to bundle with parceljs via:

parcel build src/index.ts --bundle-node-modules --target node --no-source-maps --no-minify

I am curious to see what we get when bundling (tree shaking, optimizing for containerization, etc.). Minification or not, I would like to see the results of this if it worked. We'll stick with npm install and the full build for now.

Hiredis isn't abandon (last PR was 10 days ago). However, I'd entertain a PR @sookoll for an update to 3.0.

Hiredis isn't abandon (last PR was 10 days ago). However, I'd entertain a PR @sookoll for an update to 3.0.

Sorry, I mean hiredis-node obviously. Didn't think that somebody could think out of node environment here.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

twappworld picture twappworld  路  7Comments

shmendo picture shmendo  路  6Comments

lemon707 picture lemon707  路  3Comments

dotSlashLu picture dotSlashLu  路  5Comments

adamgajzlerowicz picture adamgajzlerowicz  路  4Comments