nats-io / nkeys.js

NKeys for JavaScript - Node.js, Browsers, and Deno.
Apache License 2.0
20 stars 6 forks source link

[@nats-io/nats-core] [DEBUG] Indirect calls to "require" will not be bundled [indirect-require] #41

Closed bit-app-3000 closed 2 weeks ago

bit-app-3000 commented 3 months ago

Observed behavior

esbuild dev bundle

[DEBUG] Indirect calls to "require" will not be bundled [indirect-require]

../../node_modules/tweetnacl/nacl-fast.js:2378:20:
      2378 │   } else if (typeof require !== 'undefined') {
           ╵                     ~~~~~~~

Expected behavior

nacl-fast.js as ESM module

Server and client version

"@nats-io/nats-core": "^3.0.0-25"

"esbuild": "^0.23.1"

Host environment

No response

Steps to reproduce

No response

aricart commented 3 months ago

I am not sure how to tackle this - possibly will need to regenerate the nacl library for two targets this way require won't confuse esbuild....

@caspervonb what do you think?

aricart commented 3 months ago

The other choice is to bump the min runtime up - all this complexity is likely about the differing runtimes....

aricart commented 2 weeks ago

So not quite sure - perhaps it was an issue - but here it goes:

mkdir p
npm init -y
npm install @nats-io/nats-core
npm install @nats-io/jetstream

Make a program that references nkeys (the dep you are seeing there) - main.cjs

const { wsconnect, nkeys } = require("@nats-io/transport-node");
const { Kvm } = require("@nats-io/kv");
(async () => {
    const a = await nkeys.createAccount();
    console.log(a.getPublicKey());
    const nc = await wsconnect({ servers: "wss://demo.nats.io:8443" });
    const kvm = new Kvm(nc);

    for await (const s of kvm.list()) {
      console.log(s.bucket);
    }

    await nc.drain();
})();
node main.cjs

node main.cjs
ABSIARRAUVLW6QFRUZ7Q3WJP5NCVUUFH5B7RQD54PYPYL537JMLNQ2D6
DEVICE_BIRTH
H101_fsm_data
H101_fsm_state
HXm5PIMBNnBdYrr5A6SeAG
L9D92j5TQrjXn6WojsFBtC
MY_KV
...
esbuild --platform=node --bundle main.cjs > out.cjs
node out.cjs
node out.cjs
ACJBPAABSJB5DNKMJ7NC2IM2DFNC7Q5YQZWKJ7FBVRYEFYEXA5XGRDYC
DEVICE_BIRTH
H101_fsm_data
H101_fsm_state
HXm5PIMBNnBdYrr5A6SeAG
L9D92j5TQrjXn6WojsFBtC
MY_KV
One
SN_TEST
WHITEBOARD
WhoL8SAl1Qxq1XrLAl8Z3G
X
afanasy
all_cabinets
aricart commented 2 weeks ago

Works for me but I have been adjusting things in the bundles:

 npm ls -a
bundle-t@1.0.0 /private/tmp/bundle-t
├─┬ @nats-io/kv@3.0.0-21
│ ├─┬ @nats-io/jetstream@3.0.0-27
│ │ └── @nats-io/nats-core@3.0.0-40 deduped
│ └─┬ @nats-io/nats-core@3.0.0-40
│   ├── @nats-io/nkeys@1.2.0-7 deduped
│   └── @nats-io/nuid@2.0.1-2 deduped
└─┬ @nats-io/transport-node@3.0.0-26
  ├── @nats-io/nats-core@3.0.0-40 deduped
  ├─┬ @nats-io/nkeys@1.2.0-7
  │ └── tweetnacl@1.0.3
  └── @nats-io/nuid@2.0.1-2
aricart commented 2 weeks ago

Nope I see it - this happens with the JSR versions of the library. @bit-app-3000 Thank you for finding this.