Error TS2339: Property 'replace' does not exist on type 'string | URL'.
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.
-
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.
-
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
- 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-metadataversion: v6.1.0
Steps to reproduce
- run npm install
- 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!
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)
We will cut a release that will pull in this fix shortly:
- https://github.com/googleapis/gcp-metadata/pull/633