ngrok / ngrok-javascript

Embed ngrok secure ingress into your Node.js apps with a single line of code.
https://ngrok.com
Apache License 2.0
94 stars 18 forks source link

Error: Failed to convert napi value String into rust type `u32` #133

Closed devxoul closed 6 months ago

devxoul commented 6 months ago

Hi, I'm getting error:

Error: Failed to convert napi value String into rust type `u32`
    at Object.ngrokForward (/my-app/node_modules/@ngrok/ngrok/index.js:620:18)
    at /my-app/packages/ngrok/src/index.js:33:33
    at Object.<anonymous> (/my-app/packages/ngrok/src/index.js:44:3)

The code I've used:

const ngrok = require('@ngrok/ngrok')
ngrok.connect({ subdomain, port })

Environments:

$ node -v
v20.11.1
$ yarn -v
4.1.1

Please mention me if more information is needed. Thanks you guys for your great work :+1:

bobzilladev commented 6 months ago

Hi, thanks for writing in! What's happening there is it is passing in port as a string argument, but it is required to be a number. Also note that subdomain logs an error and is unused.

Something like this may work for what you are trying to do (a modification of examples/ngrok-forward-minimal.js)

const ngrok = require("@ngrok/ngrok");
const subdomain = 'localhost';
const port = 8080;
(async function () {
  const listener = await ngrok.forward({ host: subdomain, port: port, authtoken_from_env: true });
  console.log(`Ingress established at: ${listener.url()}`);
})();

Here are all the options available to pass in: interfaces/Config. Hopefully that is helpful!

bobzilladev commented 6 months ago

Hello again,

This change will be in the next release, which will try to parseInt a string port in the Config at that point as a convenience. Thanks for the feedback!

bobzilladev commented 6 months ago

Going to close out this issue, feel free to write in if anything else comes up. Thanks again!