3

I am trying to use google-auth-library with a react app but am getting various errors which seem to indicate missing dependencies. The errors are all in a format similar to this:

Module not found: Error: Can't resolve 'buffer' in '/private/tmp/minimal-example/node_modules/buffer-equal-constant-time'

The error messages include details on how to add a polyfill for the missing dependencies, but even after going through and adding all these polyfills I am unable to use the library. The logs for the development server still show errors for missing files, and the browser console has the following error:

GET http://metadata.google.internal./computeMetadata/v1/instance net::ERR_NAME_NOT_RESOLVED

Steps to reproduce:

  1. Install Node 16.13.2
  2. Create a react app npx create-react-app minimal-example
  3. Enter directory for the created project cd minimal-example
  4. Install google-auth-library npm install google-auth-library --save
  5. Add the following code to ./src/App.js const {GoogleAuth} = require('google-auth-library');
  6. Start the development server npm start
  7. Observe errors

What am I doing wrong?

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Tim Brier
  • 31
  • 2

1 Answers1

0

I Have the same problem with same google-auth-library package!

This is a problem with using webpack 5 on React scripts=> v5

Have three solutions to resolve:

  1. downgrade react-scripts to version 4.0.3. on package.json file.
  2. Overwrite the config webpack config, but, i will need install react-app-rewired to do this, because react app not have webpack.config on tree app files.
  3. you can eject the script to root folder executing npm run eject, but caution, this action is permanent, more here: https://stackoverflow.com/a/48395890

Some people answered this problem in How to Polyfill node core modules in webpack 5 and https://github.com/facebook/create-react-app/issues/12072

Marcos Furquim
  • 990
  • 8
  • 12