question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

1) Is this a client library issue or a product issue?

It takes a very long time for require('googleapis') to run, because it eagerly requires every API submodule. Notwithstanding the fact that the source code uses static import rather than require, this package could most likely be built in such a way that submodules were required lazily, so that in code like this, for example…

const { google } = require('googleapis');

const auth = google.auth.fromJSON(credentials);
auth.scopes = ['https://www.googleapis.com/auth/drive.readonly'];

const client = google.drive('v3');
const { data } = await client.files.export(file);

…only the submodules for google.auth and google.drive would be required.

Alternatively, or additionally, exposing submodules directly could solve the problem:

const { fromJSON } = require('googleapis/auth');
const auth = fromJSON(credentials);

const client = require('googleapis/drive/v3');
const { data } = await client.files.export(file);

2) Did someone already solve this?

Couldn’t find any prior discussion

3) Do you have a support contract?

No

Environment details

  • OS: MacOS
  • Node.js version: 12.18.3
  • npm version: 6.14.6
  • googleapis version: 59

Steps to reproduce

function timed_require(x) {
  const start = Date.now();
  const mod = require(x);
  console.log(`required ${x} in ${Date.now() - start}ms`);
  return mod;
}

timed_require('googleapis');

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

10reactions
bcoecommented, Mar 26, 2021

@alexblack wow, this is a blast from the past 😆, so I work on client libraries at Google now.


@alexblack @Rich-Harris @haohaolee, we just started publishing individual libraries from googleapis, which should significantly speed up startup/compile time:

You can find them under the @googleapis namespace on npm. Once you install a dependency, it should work almost identically to using the top level module, e.g.,

npm i @googleapis/drive
const drive = require('@googleapis/drive')
const auth = new drive.auth.GoogleAuth({
  // Scopes can be specified either as an array or as a single, space-delimited string.
  scopes: ['https://www.googleapis.com/auth/drive.readonly']
});
const authClient = await auth.getClient();
const client = drive.drive({
  version: 'v3',
  auth: authClient
});
const { data } = await client.files.export({fileId: 'abc123', mimeType: 'application/text'});
0reactions
bcoecommented, Aug 23, 2022

Closing this issue, now that we have the ability to install individual APIs. Let us know if you continue to have any issues.

Read more comments on GitHub >

github_iconTop Results From Across the Web

8 Ways to Fix Slow Boot Times in Windows 10 - MakeUseOf
8 Ways to Fix Slow Boot Times in Windows 10 · 1. Disable Fast Startup · 2. Adjust Paging File Settings · 3....
Read more >
How to Fix Slow Startup on Windows 10 | SoftwareKeep
Windows 10 startup is slow? We've compiled 7 working solutions to help you fix slow startup on Windows 10.
Read more >
Full Guide to Fix Windows 10 Slow Boot After Update - EaseUS
Fix 2. Disable unnecessary startup programs in Task Manager, Too many startup programs will slow down the computer. Right-click the taskbar, ...
Read more >
Fix the Windows 10 Slow Boot Issue: 9 Easy Solutions
How can I fix a slow boot time in Windows 10? · 1. Use the Windows 10 Startup Manager · 2. Update your...
Read more >
Solved: Windows 10/11 Slow Boot [2022 Guide] - Driver Easy
How do I fix Windows 10 slow boot? · Disable Fast Startup · Disable Processes with High Startup Impact · Update your graphics...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found