Skip to content

Error while building with webpack #790

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

Closed
Dindaleon opened this issue Jul 28, 2015 · 8 comments
Closed

Error while building with webpack #790

Dindaleon opened this issue Jul 28, 2015 · 8 comments
Labels

Comments

@Dindaleon
Copy link

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?

@erinishimoticha
Copy link
Contributor

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

@blainsmith
Copy link
Contributor

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

@BridgeAR
Copy link
Contributor

BridgeAR commented Sep 4, 2015

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

@richburdon
Copy link

richburdon commented Nov 29, 2016

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'
      },
    ]
  },
});

@monte-hayward
Copy link

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

@outsidenote
Copy link

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

thenengah added a commit to thenengah/connect-redis that referenced this issue Feb 11, 2018
@kevupton
Copy link

yarn add hiredis
npm i --save hiredis

Simple solution without a hack

@z3dtech
Copy link

z3dtech commented Jun 13, 2019

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$/)
  ],

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

No branches or pull requests

9 participants