Node.js Client TypeError [ERR_INVALID_URL]: Invalid URL
Hello, I am trying to deploy a 1Password Connect Server via Docker as per your instructions but, I am getting the following error whenever I run the nodejs app code.
Please, could you help me?
P.S.: Regarding the myVaultId shown in the URL below, I am using the vault id of the vault I gave permission to the integration server. I managed to get the vault id via 1Password CLI. it is a string with twenty-six characters.
TypeError [ERR_INVALID_URL]: Invalid URL at new NodeError (node:internal/errors:363:5) at onParseError (node:internal/url:536:9) at new URL (node:internal/url:612:5) at RequestAdapter.normalizeURL (D:\Downloads\nodejs\1Password-Secret-Automation\node_modules\@1password\connect\dist\lib\requests.js:56:41) at RequestAdapter.<anonymous> (D:\Downloads\nodejs\1Password-Secret-Automation\node_modules\@1password\connect\dist\lib\requests.js:45:53) at Generator.next (<anonymous>) at D:\Downloads\nodejs\1Password-Secret-Automation\node_modules\@1password\connect\dist\lib\requests.js:8:71 at new Promise (<anonymous>) at __awaiter (D:\Downloads\nodejs\1Password-Secret-Automation\node_modules\@1password\connect\dist\lib\requests.js:4:12) at RequestAdapter.sendRequest (D:\Downloads\nodejs\1Password-Secret-Automation\node_modules\@1password\connect\dist\lib\requests.js:39:16) { input: 'v1/vaults/myVaultId/items/', code: 'ERR_INVALID_URL'"
1Password Version: 7.7.810
Extension Version: Not Provided
OS Version: Microsoft Windows 10.0.19043.1081
Sync Type: Not Provided
Comments
-
Hi @fbi ! That's definitely frustrating, so thank you for reporting this issue.
It looks like the module isn't able to parse the server URL you provided when initializing the SDK:
import { OnePasswordConnect } from "@1password/connect"; const op = OnePasswordConnect({ serverURL: "http://localhost:8080", // this needs to be a valid URL with http:// or https:// token: "my-token" });
Could you confirm that the
serverURL
argument is a valid URL?I was able to reproduce the issue with this test script:
# example.js const {OnePasswordConnect} = require("@1password/connect"); const op = OnePasswordConnect({serverURL: "anInvalidUrl", token: "example"}); op.listVaults().then(console.log).catch(console.error); # TypeError [ERR_INVALID_URL]: Invalid URL: anInvalidUrl
0 -
Hello @David_ag. Thanks for the reply. Apparently, the issue is related to the Microsoft Windows environment. I use the Docker Desktop app on my Windows 10 running Linux containers on my initial try. On this occasion, I received an invalid URL error. Although as soon as I tried the same files on my Mac, everything worked fine. So far, I am happy that I managed to see the vanilla code working, but I need to have it on the Windows environment as this is where the project will be deployed. Please, would you be able to guide me on how to set up the 1Password Secrets Automation on Windows?
0 -
Could you provide an example of how you're passing the server URL to the
OnePasswordConnect
function? Are you using environment variables or some other method?0 -
Yes, I am passing it via a Windows environment variable. In reality, I am passing these variables (OP_CONNECT_HOST, OP_CONNECT_TOKEN, OP_VAULT, SECRET_STRING) as system environment variables.
0 -
Thanks for the information!
It sounds like either the Windows environment variable is never set or there's a formatting issue with the environment variable. Have you tried doing a
console.log()
to print theOP_CONNECT_HOST
variable in your script or app before you pass it to the Connect SDK instance?The log statement would help isolate whether Node is unable to read the environment variables in Windows or if some other process is modifying the OP_CONNECT_HOST environment variable you're setting.
0 -
Hello David_ag. Thanks for the support. I followed your advice, and the script printed the environment variables values correctly before it tries to connect to the SKD instance. However, the same error persists to happen.
Edit: Apparently, I found the problem related to this
code: 'ERR_INVALID_URL'
. For theOP_CONNECT_HOST
environment variable, I have been usinglocalhost:8080
, however, as soon as I added thehttp://
to the URL, it seems that the error is gone. Sorry for the drama, David_ag0 -
Thanks so much for following up and sharing your solution. Please feel free to open an issue in the JS SDK to improve the error messaging in this case.
0