denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
97.48k stars 5.38k forks source link

error: Uncaught TypeError: Error parsing args at position 0: serde_v8 error: invalid type; expected: buffer, got: unknown with node module #19935

Closed Asguho closed 1 year ago

Asguho commented 1 year ago

Describe the bug when using the mineflayer with deno instead of node it resolves in a TypeError Steps to Reproduce

  1. Create a script with the contents
    
    import mineflayer from 'npm:mineflayer';

const bot = mineflayer.createBot({ username: 'bot', host: 'localhost', version: '1.20.1', port: '2555', });

bot.on('inject_allowed', () => { console.log('Inject allowed'); }); bot.on('login', () => { console.log('Succesfully logged in!'); }); bot.on('spawn', () => { console.log('Succesfully spawned in!'); });

2. Execute the command 
```bash
 deno run --allow-all index.js
  1. See error
    error: Uncaught TypeError: Error parsing args at position 0: serde_v8 error: invalid type; expected: buffer, got: unknown      
    at Object.publicEncrypt (ext:deno_node/internal/crypto/cipher.ts:182:16)
    at sendEncryptionKeyResponse (file:///C:/Users/aske/AppData/Local/deno/npm/registry.npmjs.org/minecraft-protocol/1.43.2/src/client/encrypt.js:49:52)
    at gotSharedSecret (file:///C:/Users/aske/AppData/Local/deno/npm/registry.npmjs.org/minecraft-protocol/1.43.2/src/client/encrypt.js:28:9)
    at ext:deno_node/internal/crypto/_randomBytes.ts:42:17
    at Object.action (ext:deno_web/02_timers.js:153:11)
    at handleTimerMacrotask (ext:deno_web/02_timers.js:67:10)
    at eventLoopTick (ext:core/01_core.js:189:21)

Expected behavior

Inject allowed
Succesfully logged in!'
Succesfully spawned in!'

Environment

kt3k commented 1 year ago

Looks like we need to type cast the input in publicEncrypt in ext/node/polyfills/internal/crypto/cipher.ts

bartlomieju commented 1 year ago

@littledivy please take a look, that should be a quick fix.

Asguho commented 1 year ago

Is there any estimate on what update this fix will land in?

Asguho commented 1 year ago

The pull request fixed the issue, but now i get a new error: "error: Uncaught Error: ASN.1 error: PEM error: PEM Base64 error: invalid Base64 encoding". Should i make a new issue with this error?

bartlomieju commented 1 year ago

@Asguho please do