Skip to content
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

hiredis is not being installed #1254

Closed
alewaros opened this issue Jul 11, 2017 · 14 comments
Closed

hiredis is not being installed #1254

alewaros opened this issue Jul 11, 2017 · 14 comments

Comments

@alewaros
Copy link

  • 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"
    ]
  }
}
@alewaros alewaros changed the title hired is not being installed hiredis is not being installed Jul 11, 2017
@muratgozel
Copy link

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.

@BridgeAR
Copy link
Contributor

This is an issue with webpack.

@guidobouman
Copy link

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.

@peterschussheim
Copy link

@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.

@BridgeAR
Copy link
Contributor

BridgeAR commented Sep 3, 2018

@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.

@guidobouman
Copy link

@BridgeAR See NodeRedis/node-redis-parser#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.

@peterschussheim
Copy link

@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).

👎

@demian85
Copy link

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.

@RyotaBannai
Copy link

RyotaBannai commented Apr 28, 2019

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.

@sookoll
Copy link

sookoll commented Sep 18, 2019

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.

@jduhls
Copy link

jduhls commented Sep 26, 2019

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.

@stockholmux
Copy link
Contributor

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

@sookoll
Copy link

sookoll commented Sep 26, 2019

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.

@icholy
Copy link

icholy commented Mar 28, 2022

For anyone running into this, the fix is to upgrade to v3.x which doesn't use hiredis anymore: https://github.com/redis/node-redis/blob/master/CHANGELOG.md#breaking-changes-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests