node-redis
node-redis copied to clipboard
@redis/client contains dynamic require statements that do not work with esBuild in esmodule mode
Description
When a module is built using the esbuild command esbuild index.js --entry-names=[dir]/[name] --bundle --sourcemap --sources-content=false --external:@aws-sdk --platform=node --format=esm --outdir=dist --out-extension:.js=.mjs and then run through AWS Lambda, the error Dynamic require of \"events\" is not supported occurs.
Can be replicated by just compiling one of the examples with esbuild and running it with node dist/index.mjs
// Add several values with their scores to a Sorted Set,
// then retrieve them all using ZSCAN.
import { createClient } from 'redis';
const client = createClient();
await client.connect();
await client.zAdd('mysortedset', [
{
score: 99,
value: 'Ninety Nine'
},
{
score: 100,
value: 'One Hundred'
},
{
score: 101,
value: 'One Hundred and One'
}
]);
// Get all of the values/scores from the sorted set using
// the scan approach:
// https://redis.io/commands/zscan
for await (const memberWithScore of client.zScanIterator('mysortedset')) {
console.log(memberWithScore);
}
await client.disconnect();
Node.js Version
v18.16.0
Redis Server Version
7.1
Node Redis Version
4.6.12
Platform
Linux
Logs
$ node dist/index.mjs
file:///home/ec2-user/code/sorted-set/dist/index.mjs:12
throw Error('Dynamic require of "' + x + '" is not supported');
^
Error: Dynamic require of "events" is not supported
at file:///home/ec2-user/code/sorted-set/dist/index.mjs:12:9
at node_modules/@redis/client/dist/lib/client/socket.js (file:///home/ec2-user/code/sorted-set/dist/index.mjs:8234:20)
at __require2 (file:///home/ec2-user/code/sorted-set/dist/index.mjs:15:50)
at node_modules/@redis/client/dist/lib/client/index.js (file:///home/ec2-user/code/sorted-set/dist/index.mjs:11438:20)
at __require2 (file:///home/ec2-user/code/sorted-set/dist/index.mjs:15:50)
at node_modules/@redis/client/dist/index.js (file:///home/ec2-user/code/sorted-set/dist/index.mjs:13123:20)
at __require2 (file:///home/ec2-user/code/sorted-set/dist/index.mjs:15:50)
at node_modules/redis/dist/index.js (file:///home/ec2-user/code/sorted-set/dist/index.mjs:17644:20)
at __require2 (file:///home/ec2-user/code/sorted-set/dist/index.mjs:15:50)
at file:///home/ec2-user/code/sorted-set/dist/index.mjs:17687:28
Node.js v18.19.0