Closed JustinBaySpoton closed 1 week ago
Is this from npm or jsr?
npm
I am not able to reproduce that package.json
{
"type": "module",
"dependencies": {
"@nats-io/jetstream": "^3.0.0-9",
"@nats-io/nats-core": "^3.0.0-25",
"typescript": "^5.5.4"
}
}
tsconfig
{
"compilerOptions": {
"target": "esnext",
"module": "nodenext",
"outDir": "./lib/",
"moduleResolution": "nodenext",
"sourceMap": true,
"declaration": true,
"allowJs": true,
"removeComments": false
},
"include": [
"./main.ts"
]
}
import { wsconnect } from "@nats-io/nats-core";
import {AckPolicy, jetstream, jetstreamManager} from "@nats-io/jetstream"
console.log("before connect");
const nc = await wsconnect({servers: ["wss://demo.nats.io:8443"]});
console.log("connected")
const jsm = await jetstreamManager(nc);
const n = "teststream-sdfkdfkdfdkfdf"
const si = await jsm.streams.add({name: n, subjects: [n]});
console.log("created stream");
const ci = await jsm.consumers.add(n, {durable_name: n, ack_policy: AckPolicy.Explicit});
console.log("created consumer");
const js = jsm.jetstream();
const cc = await js.consumers.get(n,n);
const iter = await cc.fetch({max_messages: 3, expires: 2_000});
(async () => {
const status = await iter.status();
for await(const s of status) {
console.log(s);
}
})();
for await(const m of iter) {
console.log(m.subject);
}
await jsm.streams.delete(n);
await nc.close();
aricart@mac-studio /p/t/ni> tsc
aricart@mac-studio /p/t/ni> node lib/main.js
before connect
connected
created stream
created consumer
{
type: 'next',
data: {
batch: 3,
max_bytes: 0,
idle_heartbeat: 1000000000,
expires: 2000000000
}
}
{ type: 'discard', data: { msgsLeft: 3, bytesLeft: 0 } }
aricart@mac-studio /p/t/ni>
possible that an older bundle is doing what you see - I have newer ones - perhaps
npm install @nats-io/nats-core@next
Please reopen if you don't get it to work with the bundles I have.
Thanks -- looks like this was at least a tsconfig issue on our end. ModuleResolution needs to be nodenext
and not node
. Updating packages did not resolve it, but that did.
Observed behavior
With some code like this in my project:
In
nats.ws
this worked fine. Withnats.js
, after adjusting imports to migrate, TypeScript is giving an error on theof iterator
bit, claiming it doesn't implement the iterator protocol:This is seemingly because of a bad path in published types. This line is in the jetstream type defs,
node_modules/@nats-io/jetstream/lib/types.d.ts
:If I change this to the path I see on disk, everything works fine:
The runtime JS works just fine. The issue is limited to types.
Expected behavior
No errors on
of iterator
aboveServer and client version
Host environment
No response
Steps to reproduce
No response