I'm trying to use the redis module to look up a key value in a redis table. However, the very import itself (import redis from 'redis') is throwing the following error:
Failed to compile.
./node_modules/bindings/bindings.js Module not found: Can't resolve 'fs' in '/home/ubuntu/proost/web/node_modules/bindings'
Build error occurred Error: > Build failed because of webpack errors at build (/home/ubuntu/proost/web/node_modules/next/dist/build/index.js:6:847) error Command failed with exit code 1.
I tried reading up the module's documentation but couldn't find any reference to this issue. For what it's worth, my next.config.js file (a custom NextJS extension of Webpack) looks like this:
/* eslint-disable no-unused-vars */
import path from 'path';
import glob from 'glob';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import webpack from 'webpack';
import dotenv from 'dotenv';
import OptimizeCSSAssetsPlugin from 'optimize-css-assets-webpack-plugin';
import withSass from '@zeit/next-sass';
import withCSS from '@zeit/next-css';
import withPurgeCss from 'next-purgecss';
// dotenv.config();
const { parsed: localEnv } = dotenv.config();
module.exports = withCSS(withSass(withPurgeCss({
distDir: '.build',
purgeCssPaths: [
'pages/**/*',
'components/**/*',
],
webpack: (config, { dev, isServer }) => {
if (isServer) {
return config;
}
config.plugins.push(
new webpack.DefinePlugin({
'process.env': {
BASE_URL: JSON.stringify(process.env.BASE_URL),
REDIS_HOST: JSON.stringify(process.env.REDIS_HOST),
REDIS_PORT: JSON.stringify(process.env.REDIS_PORT),
},
}),
new webpack.EnvironmentPlugin(localEnv),
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1,
}),
);
config.optimization.minimizer.push(
new OptimizeCSSAssetsPlugin({}),
);
return config;
},
})));
Any way to fix this problem?