【问题标题】:Getting "Module not found" error when trying to use the Google APIs Node.js client尝试使用 Google APIs Node.js 客户端时出现“未找到模块”错误
【发布时间】:2016-12-30 02:20:43
【问题描述】:

我正在尝试在新的 React Web 应用程序上使用 Google API Node.js client。 这是我的 package.json

{
  "name": "onboarding",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "react-scripts": "0.8.4"
  },
  "dependencies": {
    "googleapis": "^15.1.0",
    "react": "^15.4.1",
    "react-dom": "^15.4.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

当我尝试访问 App.js 中的 API 时:

var google = require('googleapis');

它不会编译并给我:

Failed to compile.

Error in ./~/google-auth-library/lib/auth/googleauth.js
Module not found: 'child_process' in /home/jack/onboarding/node_modules/google-auth-library/lib/auth

 @ ./~/google-auth-library/lib/auth/googleauth.js 21:11-35

Error in ./~/googleapis/lib/generator.js
Module not found: 'swig' in /home/jack/onboarding/node_modules/googleapis/lib

 @ ./~/googleapis/lib/generator.js 21:11-26

Error in ./~/googleapis/lib/generator.js
Module not found: 'js-beautify' in /home/jack/onboarding/node_modules/googleapis/lib

 @ ./~/googleapis/lib/generator.js 22:15-37

我可以通过手动将js-beautifyswig 添加到依赖项来消除错误,但这不适用于child_process。无论哪种方式,我都觉得我在这里做错了什么。 var google = require('googleapis'); 不应该在 react App.js 代码中吗?任何建议将不胜感激。

【问题讨论】:

  • 你试过rm -rf node_modules 并做一个新鲜的npm install 吗?
  • 是的,我有。我想知道我是否不应该将var google = require('googleapis'); 放入 react App.js 文件中
  • 你是对的。 googleapis 是一个适用于所有 Google API 的节点库。不能在前端使用。
  • 他们提供可以从前端使用的库吗?

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


【解决方案1】:

我认为我遇到问题的原因是我试图从前端访问 API。

【讨论】:

    猜你喜欢
    • 2022-01-20
    • 1970-01-01
    • 2017-01-19
    • 1970-01-01
    • 2019-12-13
    • 1970-01-01
    • 2019-04-19
    • 2018-08-20
    • 2020-08-18
    相关资源
    最近更新 更多