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

Replace deprecated .data property with .body for compatibility with node-fetch@3.x #677

Closed
jamesdesantiago opened this issue Dec 30, 2024 · 1 comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@jamesdesantiago
Copy link

Environment details:

OS: Windows 10
Node.js version: v22.12.0
npm version: v10.9.0
gaxios version: v6.7.1

Steps to reproduce

  1. Install googleapis or another library that depends on gaxios and uses node-fetch@3.x:
    npm install googleapis
    
  2. Create a simple script that makes an authenticated request using googleapis:
const { google } = require('googleapis');

async function testGaxios() {
  const auth = new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  });

  const authClient = await auth.getClient();
  const projectId = await auth.getProjectId();

  const res = await authClient.request({
    url: `https://cloudresourcemanager.googleapis.com/v1/projects/${projectId}`,
  });

  console.log(res.data);
}

testGaxios().catch(console.error);
  1. Run the script:
node index.js
  1. Observe the deprecation warning in the console:
(node:12345) [https://github.com/node-fetch/node-fetch/issues/1000 (request)] DeprecationWarning: .data is not a valid RequestInit property, use .body instead

Description

The _defaultAdapter method in gaxios passes .data as a property of the opts object to node-fetch. With node-fetch@3.x, .data is no longer a valid property and should be replaced with .body. This results in the following deprecation warning:

(node:12345) [https://github.com/node-fetch/node-fetch/issues/1000 (request)] DeprecationWarning: .data is not a valid RequestInit property, use .body instead

Suggested Fix

Update _defaultAdapter to translate .data into .body before making the request. Example:

if (opts.data) {
    opts.body = opts.data;
    delete opts.data;
}

This change ensures compatibility with node-fetch@3.x and removes the deprecation warning.

Expected Behavior:

gaxios should internally convert .data to .body before passing the options to node-fetch. This ensures compatibility with node-fetch@3.x and eliminates the deprecation warning.

@jamesdesantiago jamesdesantiago added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Dec 30, 2024
@d-goog
Copy link
Contributor

d-goog commented Jan 4, 2025

Thanks, this has been completed in:

And will release in:

@d-goog d-goog closed this as not planned Won't fix, can't repro, duplicate, stale Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

2 participants