Comments (6)
I have the same problem, I'm getting TypeError: LZ4Codec is not a constructor
.
This was on the beta with: npm install [email protected]
The full error:
TypeError: LZ4Codec is not a constructor
at Object.<anonymous> (/xxx/public/server/controller/kafka.js:13:21)
at Module._compile (node:internal/modules/cjs/loader:1116:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1169:10)
at Module.load (node:internal/modules/cjs/loader:988:32)
at Module._load (node:internal/modules/cjs/loader:829:12)
at Function.c._load (node:electron/js2c/asar_bundle:5:13343)
at Module.require (node:internal/modules/cjs/loader:1012:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/xxx/public/server/controller/consumer.js:1:15)
at Module._compile (node:internal/modules/cjs/loader:1116:14)
npm run electron:start exited with code 7
I'm doing an electron app.
On the server side I have kafka.js
file which I use, with the code:
const { Kafka, CompressionTypes, CompressionCodecs } = require("kafkajs");
const { LZ4Codec } = require('kafkajs-lz4');
const username = "nope";
const password = "nope";
const sasl =
username && password ? { username, password, mechanism: "plain" } : null;
const ssl = !!sasl;
// LZ4 compression
const LZ4Instance = new LZ4Codec()
CompressionCodecs[CompressionTypes.LZ4] = LZ4Instance.codec;
const kafka = new Kafka({
clientId: "noper",
brokers: ["nope"],
ssl,
sasl,
});
module.exports = kafka;
Then consumer.js
:
const kafka = require("./kafka");
const io = require("../socket");
const consumer = async (topic) => {
const consumer = kafka.consumer({ groupId: "test-group" });
try {
await consumer.connect();
} catch (e) {
console.log("Error: couldn't connect to Kafka");
return;
}
console.log("Connected to Kafka!");
try {
await consumer.subscribe({ topic, topic });
} catch (e) {
console.log("Error: couldn't subscribe to topic.");
return;
}
console.log("Kafka consumer subscribed.");
console.log("Consuming...");
try {
await consumer.run({
eachMessage: async ({ topic, partition, message }) => {
console.log("Received message: " + message.value.toString());
io.getIO().emit("events", {
action: "consume",
event: message.value.toString(),
});
},
});
} catch (e) {
console.log("Couldn't consume message");
}
};
module.exports = consumer;
I hope this helps narrow it down somehow. Ask if you need more specific info.
from kafkajs-lz4.
@link2malkeet Please provide a minimal, complete and verifiable example for your issue, as they're both valid exports, they can work side-by-side in CommonJS and ES6 environments, and the latest beta version has been verified to work.
To verify yourself —
- Clone this repo.
- Add this package itself as a dependency.
yarn add [email protected]
- Modify this line to import the package you just added.
- import LZ4Codec from '../src/index'; + import LZ4Codec from 'kafkajs-lz4';
- Run tests (you need Docker for this).
yarn run test
from kafkajs-lz4.
HI @paambaati
I will try again later
Just to summarize what I know or understand, the main index file works with default exports only, we don't need to define module.exports in typescript.
Thanks
from kafkajs-lz4.
Hi @paambaati Just following up on this, is the beta version going to be promoted?
from kafkajs-lz4.
@AlanKavanagh Can you confirm the beta version works for you? It'd be great if you can tell us a little about your Kafka cluster and how long you've been using the beta version.
from kafkajs-lz4.
I see below error as well:
TypeError: kafkajs_lz4_1.default is not a constructor
when using:
import LZ4Codec from 'kafkajs-lz4';
from kafkajs-lz4.
Related Issues (8)
- RuntimeError: abort(OOM). Build with -s ASSERTIONS=1 for more info. HOT 1
- Does not work on node 18 HOT 12
- Upgrade dependencies for vulnerabilities HOT 1
- Snyk Error because of [email protected] : CVSS 7.5 - High Severity
- npm package appears corrupt HOT 15
- install broken since lz4 updated to 6.0.4 HOT 1
- yarn add kafkajs-lz4 issue HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kafkajs-lz4.