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

Googleapis return "Module not found: can't resolve fs" when running a project #3174

Closed
Geccles opened this issue Mar 2, 2023 · 7 comments
Closed
Labels
needs more info This issue needs more information from the customer to proceed. 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

@Geccles
Copy link

Geccles commented Mar 2, 2023

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?

  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:
  • Node.js version: 19.5.0
  • npm version: 9.4.0
  • googleapis version: 112.0.0

Steps to reproduce

  1. install googleapis
  2. run project and I see the following error:
error - ./node_modules/gcp-metadata/build/src/gcp-residency.js:19:0
Module not found: Can't resolve 'fs'

Import trace for requested module:
./node_modules/gcp-metadata/build/src/index.js
./node_modules/google-auth-library/build/src/auth/googleauth.js
./node_modules/google-auth-library/build/src/index.js
./node_modules/googleapis/build/src/index.js

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

Thanks!

@Geccles Geccles 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 Mar 2, 2023
@sofisl sofisl added the needs more info This issue needs more information from the customer to proceed. label Mar 2, 2023
@sofisl
Copy link
Contributor

sofisl commented Mar 2, 2023

Hi @Geccles, could you provide the code you are attempting to run? Thanks in advance.

@Geccles
Copy link
Author

Geccles commented Mar 2, 2023

@sofisl

This is my function and then I just call it in another file. Let me know if there's anything else you may need.
The credentials are in a json like so:

{
  "type": "service_account",
  "project_id": "our_project_id",
  "private_key_id": "our_private_key",
  "private_key": "-----BEGIN PRIVATE KEY-----"
  "client_email": "our_client_email",
  "client_id": "our_client_id",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "our_cert_url"
}
export function getGoogleDocFiles() {
  const { google } = require('googleapis')

  const credentials = require('../../credentials.json')
  const scopes = [
    'https://www.googleapis.com/auth/drive'
  ]
  const auth = new google.auth.JWT(
    credentials.client_email, null,
    credentials.private_key, scopes
  )
  console.log(auth)
  const drive = google.drive({ version: "v3", auth })
  console.log(drive)

  drive.files.list({}, (err, res) => {
    if (err) throw err
    const files = res.data.files
    if (files.length) {
      files.map((file) => {
      console.log(file)
    })
    } else {
      console.log('No files found')
    }
  })
}

@xxmafiaxxx
Copy link

any updates on this
happening to me too

@JuanTorchia
Copy link

JuanTorchia commented Jun 1, 2023

The error you're seeing is common when trying to use certain Node.js modules, such as fs (file system), on the client side of a JavaScript application. This is because these modules are designed to be used in the Node.js environment on the server, not in the browser.

In your case, it appears that you're trying to use the googleapis module on the client side of your application. This module relies on other Node.js modules, such as fs, which are not available in the browser.

To fix this issue, you should move any code that uses googleapis to the server side of your application.

@jakin6
Copy link

jakin6 commented Jan 15, 2024

For me i removed "use client" where i call it on page.tsx and it works. Because my issue, what to call signout() function on page.tsx of nextAuth with google and when i remove there was not issue all works fine

Copy link

This has been closed since a request for information has not been answered for 15 days. It can be reopened when the requested information is provided.

@gitDeveloper3
Copy link

You have to set some environment variable. I found out after i deleleted it a google-related env variable and got the error. The bad news is that i dont know it since git wasnt tracking my the .env.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info This issue needs more information from the customer to proceed. 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

6 participants