Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError [ERR_INVALID_URL] after updating to 4.2.3 #1193

Closed
youngcholo opened this issue Oct 28, 2020 · 12 comments
Closed

TypeError [ERR_INVALID_URL] after updating to 4.2.3 #1193

youngcholo opened this issue Oct 28, 2020 · 12 comments
Labels

Comments

@youngcholo
Copy link

youngcholo commented Oct 28, 2020

I'm getting this error after updating to 4.2.3

TypeError [ERR_INVALID_URL] [ERR_INVALID_URL]: Invalid URL: [object Object]
    at onParseError (internal/url.js:243:9)
    at new URL (internal/url.js:319:5)
    at Object.connect (C:\Program Files (x86)\NLT\bin\node_modules\mqtt\lib\connect\index.js:64:18)
    at Object.connect (C:\Program Files (x86)\NLT\bin\node_modules\async-mqtt\index.js:139:25)
mqtt: {
    connection: {
      host: {
        doc: "The URL of the mqtt server.",
        format: "mqtt-url",
        default: "tcp://localhost",
        env: "MQTT",
        arg: "mqtt"
      },
      port: {
        doc: "The port to connect to for the mqtt server.",
        format: "port",
        default: 1883,
        env: "MQTT_PORT"
      }
    }
  }

const connectionString = url.parse(conf.get("mqtt").connection.host);
connectionString.port = conf.get("mqtt").connection.port;
mqtt.connect(connectionString, { clientId: this._clientId, clean:false })

this was working yesterday with 4.2.1

AB#8679346

@YoDaMa
Copy link
Contributor

YoDaMa commented Oct 28, 2020

@youngcholo thanks for filing the issue. What is the connection string you are providing?

@YoDaMa
Copy link
Contributor

YoDaMa commented Oct 28, 2020

is there a minimal repro you can provide?

@yurievangelista
Copy link

Same is happening here with a pre-signed URL string.
What I've managed to observe is that the opts parameter in the streamBuilder function seems to lose the href property somewhere along the way, and I'm left with an empty ("/") path.
I'm using the library in a browser, if that's any help.

@youngcholo
Copy link
Author

Before 4.2.3 and as specified in the docs, " The URL can also be an object as returned by URL.parse()"
https://repl.it/join/yhjykmju-youngcholo

@YoDaMa
Copy link
Contributor

YoDaMa commented Oct 29, 2020

@youngcholo yeah looks like a bug again with the url parsing. Can you incorporate the changes from the PR linked manually and see if they fix things?

@YoDaMa
Copy link
Contributor

YoDaMa commented Oct 30, 2020

@youngcholo can you check that this is fixed in 4.2.4?

@youngcholo
Copy link
Author

Apologies for the late response. The issue still persists in 4.2.4.
https://repl.it/@youngcholo/mqtttest424

@YoDaMa
Copy link
Contributor

YoDaMa commented Oct 31, 2020

I see now. Thanks for the repl. This is an issue with the legacy support of url.parse. Will have to see if the changes should be reversed because I did not anticipate them affecting the API in this way. I do not believe though there is explicit support for url.parse() in the documentation, but since that does provide a change of support unsure if that means it should be a major version bump...

@youngcholo
Copy link
Author

Thanks for the information @YoDaMa. If we want to connect via tcp instead of passing the urlObj, we can just pass the host and port in the options, right?

mqtt.connect({ host: urlObj.host, port: urlObj.port, clientId: this._clientId, clean:false })

@YoDaMa
Copy link
Contributor

YoDaMa commented Nov 2, 2020

usually when I'm working with a URL for TCP, I will pass the port in during the connection string:

mqtt.connect('mqtt://test.mosquitto.org:1883')

@github-actions
Copy link

This is an automated message to let you know that this issue has
gone 365 days without any activity. In order to ensure that we work
on issues that still matter, this issue will be closed in 14 days.

If this issue is still important, you can simply comment with a
"bump" to keep it open.

Thank you for your contribution.

@github-actions github-actions bot added the stale label Sep 21, 2022
@github-actions
Copy link

This issue was automatically closed due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants