Skip to content

Update dependency ky to v2#90

Open
renovate[bot] wants to merge 1 commit into
mainfrom
renovate/ky-2.x
Open

Update dependency ky to v2#90
renovate[bot] wants to merge 1 commit into
mainfrom
renovate/ky-2.x

Conversation

@renovate
Copy link
Copy Markdown
Contributor

@renovate renovate Bot commented Apr 6, 2026

This PR contains the following updates:

Package Change Age Confidence
ky ^1.14.1^2.0.0 age confidence

Release Notes

sindresorhus/ky (ky)

v2.0.0

Compare Source

Breaking
New
Fixes
  • Fix beforeRequest hooks being skipped when a Request is returned (#​832) aec65db
  • Ignore non-Errors returned by beforeError hooks (#​833) a541fc0

Migration guide

Hook signatures

All hooks now receive a single state object instead of separate arguments.

hooks: {
-	beforeRequest: [(request, options) => {
+	beforeRequest: [({request, options}) => {
		request.headers.set('X-Custom', 'value');
	}],
-	afterResponse: [(request, options, response) => {
+	afterResponse: [({request, options, response}) => {
		log(response.status);
	}],
-	beforeRetry: [({request, options, error, retryCount}) => {
+	beforeRetry: [({request, options, error, retryCount}) => {
		// Same as before - beforeRetry already used an object
	}],
-	beforeError: [(error) => {
+	beforeError: [({error}) => {
		return error;
	}],
}
prefixUrl renamed to prefix
-ky('users', {prefixUrl: 'https://example.com/api/'});
+ky('users', {prefix: 'https://example.com/api/'});

Leading slashes in input are now allowed with prefix. There's also a new baseUrl option for standard URL resolution, which you may prefer over prefix.

beforeError hook receives all errors

Previously only received HTTPError. Now receives all error types. Use type guards:

+import {isHTTPError} from 'ky';

hooks: {
	beforeError: [
-		(error) => {
-			const {response} = error;
+		({error}) => {
+			if (isHTTPError(error)) {
+				const {response} = error;
+			}

			return error;
		}
	]
}
.json() on empty responses

.json() now throws a parse error on empty bodies and 204 responses instead of returning an empty string. This aligns with native JSON.parse behavior and surfaces the real issue; your code expected JSON but the server sent none.

Check the status before calling .json() if you expect empty responses:

const response = await ky('https://example.com/api');

if (response.status !== 204) {
    const data = await response.json();
}
Ky-specific options stripped from hooks

Ky-specific properties (hooks, json, parseJson, stringifyJson, searchParams, timeout, throwHttpErrors, fetch) are no longer available on the options object passed to hooks. If you need access to these values, store them in a variable outside the hook or use the context option to pass data between hooks.

searchParams merging

searchParams now merges with existing query parameters in the input URL instead of replacing them.

// v1: searchParams replaces ?existing=1
// v2: searchParams merges with ?existing=1
ky('https://example.com?existing=1', {searchParams: {added: 2}});
// => https://example.com?existing=1&added=2
HTTPError response body

error.response.json() and other body methods no longer work since the body is now automatically consumed. Use error.data instead, which has the pre-parsed response body immediately available.

-const body = await error.response.json();
-console.log(body.message);
+console.log(error.data.message);

This fixes resource leaks when catching HTTPError without consuming the body (#​633) and makes error details synchronously available (#​642). We considered cloning the response to keep both paths working, but that doubles memory usage for error bodies and adds edge cases around locked/large streams for little benefit. error.response is still available for headers and status.

Upgrading from 2.0.0-0

.json() on empty responses

The behavior changed again from the prerelease. .json() now throws instead of returning undefined for empty bodies and 204 responses. The return type is back to Promise<T> (no more | undefined).


v1.14.3

Compare Source

  • Fix empty context object being added to merged json body d7f7e73

v1.14.2

Compare Source



Configuration

📅 Schedule: Branch creation - Between 12:00 AM and 03:59 AM ( * 0-3 * * * ) in timezone Europe/Helsinki, Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Never, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

@renovate renovate Bot assigned pekkis Apr 6, 2026
@renovate
Copy link
Copy Markdown
Contributor Author

renovate Bot commented Apr 6, 2026

⚠️ Artifact update problem

Renovate failed to update an artifact related to this branch. You probably do not want to merge this PR as-is.

♻ Renovate will retry this branch, including artifacts, only when one of the following happens:

  • any of the package files in this branch needs updating, or
  • the branch becomes conflicted, or
  • you click the rebase/retry checkbox if found above, or
  • you rename this PR's title to start with "rebase!" to trigger it manually

The artifact failure details are included below:

File name: pnpm-lock.yaml
Progress: resolved 1, reused 0, downloaded 0, added 0
Progress: resolved 29, reused 0, downloaded 0, added 0
 ERR_PNPM_NO_MATCHING_VERSION  No matching version found for ky@^2.0.0 published by Sat Apr 04 2026 14:00:24 GMT+0000 (Coordinated Universal Time) while fetching it from https://registry.npmjs.org/. Version 2.0.0 satisfies the specs but was released at Mon Apr 06 2026 08:00:06 GMT+0000 (Coordinated Universal Time)

This error happened while installing a direct dependency of /tmp/renovate/repos/github/pekkis/hardcore-react-training

The latest release of ky is "2.0.0". Published at 4/6/2026 8:00:06 AM

Other releases are:
  * next: 2.0.0-0 published at 3/29/2026

If you need the full list of all 97 published versions run "$ pnpm view ky versions".

If you want to install the matched version ignoring the time it was published, you can add the package name to the minimumReleaseAgeExclude setting. Read more about it: https://pnpm.io/settings#minimumreleaseageexclude

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant