【问题标题】:google-auth-library has missing dependencies when installedgoogle-auth-library 安装时缺少依赖项
【发布时间】:2022-11-09 15:54:50
【问题描述】:

我正在尝试将 google-auth-library 与 react 应用程序一起使用,但出现各种错误,这些错误似乎表明缺少依赖项。错误都采用类似于以下的格式:

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

错误消息包括有关如何为缺少的依赖项添加 polyfill 的详细信息,但即使在完成并添加了所有这些 polyfill 之后,我也无法使用该库。开发服务器的日志仍然显示丢失文件的错误,并且浏览器控制台出现以下错误:

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

重现步骤:

  1. 安装节点 16.13.2
  2. 创建一个反应应用npx create-react-app minimal-example
  3. 进入创建项目的目录cd minimal-example
  4. 安装 google-auth-library npm install google-auth-library --save
  5. 将以下代码添加到./src/App.js const {GoogleAuth} = require('google-auth-library');
  6. 启动开发服务器npm start
  7. 观察错误

    我究竟做错了什么?

【问题讨论】:

    标签: node.js reactjs google-oauth google-api-nodejs-client


    【解决方案1】:

    我对相同的google-auth-library 包有同样的问题!

    这是在React scripts=> v5 上使用 webpack 5 的问题

    有三个解决方案来解决:

    1. react-scripts 降级到版本4.0.3。在package.json 文件上。
    2. 覆盖配置 webpack 配置,但是,我需要安装 react-app-rewired 来执行此操作,因为 react 应用在树应用文件上没有 webpack.config
    3. 您可以将脚本弹出到执行npm run eject 的根文件夹,但请注意,此操作是永久性的,更多信息请参见:https://stackoverflow.com/a/48395890

      有人在How to Polyfill node core modules in webpack 5回答了这个问题 和https://github.com/facebook/create-react-app/issues/12072

    【讨论】:

      猜你喜欢
      • 2017-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-18
      • 1970-01-01
      • 1970-01-01
      • 2020-02-19
      • 2020-01-30
      相关资源
      最近更新 更多