I have taken the sample app https://www.serverless.com/blog/react-js-on-aws-lambda and got it working, changes a few minor things. But I want to add REDIS. It is deployed by running the command "npx sls deploy". All was good until I tried to install either of these two REDIS packages. After doing "npm install redis" or "npm install ioredis"
With IOREDIS I get:
Module not found: Error: Can't resolve 'dgram' in 'c:\GitHub\Relatix\Apps\CMS\node_modules\native-dns-cache'
Module not found: Error: Can't resolve 'fs' in 'c:\GitHub\Relatix\Apps\CMS\node_modules\native-dns\lib'
Module not found: Error: Can't resolve 'dgram' in 'c:\GitHub\Relatix\Apps\CMS\node_modules\native-dns\lib'
I have tried installing each one separate, for example "npm install dgram" and "npm install fs" etc... But the errors persist.
With REDIS I get similar message for "Crypto".
I have spent hours trying different things.
Maybe the issue is with "webpack", but I'm not even sure what it really is.
serverless-react-boilerplate@0.1.0 build:browser webpack --config webpack.browser.config.js --mode production
I started all over from scratch by downloading the demo project again. If I run "npm install redis", but don't actually use it, I don't get any errors.
When I add this line to my app: const redis = require('redis');
Then I get these errors on deploy:
ERROR in ./node_modules/@redis/client/dist/lib/client/socket.js 16:12-26
Module not found: Error: Can't resolve 'net' in 'c:\GitHub\Relatix\Apps\CMS\node_modules\@redis\client\dist\lib\client'
ERROR in ./node_modules/@redis/client/dist/lib/client/socket.js 17:12-26
Module not found: Error: Can't resolve 'tls' in 'c:\GitHub\Relatix\Apps\CMS\node_modules\@redis\client\dist\lib\client'
ERROR in ./node_modules/@redis/client/dist/lib/lua-script.js 4:17-34
Module not found: Error: Can't resolve 'crypto' in 'c:\GitHub\Relatix\Apps\CMS\node_modules\@redis\client\dist\lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "crypto": false }
I have tried most of the suggestions here: Error when attempting to include Crypto module: Can't resolve 'crypto'
I have no idea what a "polyfill" is, but I will look at those instructions next.
I have tried a few things so far - more wasted hours... Was looking at the many suggestions on this post: How to Polyfill node core modules in webpack 5 and this: https://dev.to/marcinwosinek/how-to-add-resolve-fallback-to-webpack-5-in-nextjs-10-i6j
In my webpack.browser.config.js I tried this:
future: { webpack5: true},
webpack: (config) => {
config.resolve.fallback = { fs: false };
return config;
},
Resulting in these errors: [webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.sdemo to stage dev (us-east-1) - configuration has an unknown property 'webpack'. These properties are valid: object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry?, experiments?, externals?, externalsPresets?, externalsType?, ignoreWarnings?, infrastructureLogging?, loader?, mode?, module?, name?, node?, optimization?, output?, parallelism?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, snapshot?, stats?, target?, watch?, watchOptions? } -> Options object as provided by the user. For typos: please correct them. For loader options: webpack >= v2.0.0 no longer allows custom properties in configuration. Loaders should be updated to allow passing options via loader options in module.rules. Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader: plugins: [ new webpack.LoaderOptionsPlugin({ // test: /.xxx$/, // may apply this only for some modules options: { webpack: … } }) ]