gcp-metadata icon indicating copy to clipboard operation
gcp-metadata copied to clipboard

Error TS2339: Property 'replace' does not exist on type 'string | URL'.

Open ramnathnayak-ibm opened this issue 1 year ago • 1 comments

Thanks for stopping by to let us know something could be better!

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

  1. Is this a client library issue or a product issue? This is the client library for . We will only be able to assist with issues that pertain to the behaviors of this library. If the issue you're experiencing is due to the behavior of the product itself, please visit the Support page to reach the most relevant engineers.

  2. Did someone already solve this?

  • Search the issues already opened: https://github.com/googleapis/gcp-metadata/issues
  • Search the issues on our "catch-all" repository: https://github.com/googleapis/google-cloud-node
  • Search or ask on StackOverflow (engineers monitor these tags): http://stackoverflow.com/questions/tagged/google-cloud-platform+node.js
  1. Do you have a support contract? Please create an issue in the support console to ensure a timely response.

If the support paths suggested above still do not result in a resolution, please provide the following details.

Environment details

  • OS: Red Hat Enterprise Linux
  • Node.js version: v20.15.0
  • npm version: v10.7.0
  • gcp-metadata version: v6.1.0

Steps to reproduce

  1. run npm install
  2. Getting error message: src/index.ts:184:23 - error TS2339: Property 'replace' does not exist on type 'string | URL'. Property 'replace' does not exist on type 'URL'.

184 url: options.url!.replace(getBaseUrl(), getBaseUrl(SECONDARY_HOST_ADDRESS)), ~~~~~~~ Found 1 error in src/index.ts:184

Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

ramnathnayak-ibm avatar Jul 03 '24 11:07 ramnathnayak-ibm

The main branch has the correct code to handle this situation for replace function i.e. its converting the url to string first. url: options.url ?.toString() .replace(getBaseUrl(), getBaseUrl(SECONDARY_HOST_ADDRESS)), Line no 185 in gcp-metadata/src/index.ts (main)

ramnathnayak-ibm avatar Jul 03 '24 11:07 ramnathnayak-ibm

We will cut a release that will pull in this fix shortly:

  • https://github.com/googleapis/gcp-metadata/pull/633

d-goog avatar Nov 12 '24 19:11 d-goog