【问题标题】:Vue project and googleapis - will not build - child_process errorsVue 项目和 googleapis - 不会构建 - child_process 错误
【发布时间】:2018-04-15 04:25:44
【问题描述】:

目标

在 vue-cli 项目中安装和构建 googleapis 包。

示例

https://github.com/ChaddPortwine/test-googleapis

要创建这个示例,我只是:

  1. vue init webpack test-googleapis
  2. npm install
  3. npm install googleapis --save, npm install google-auth-library --save
  4. npm run dev(到目前为止,好的,应用已构建并运行)
  5. 添加行,import googleapis from 'googleapis'main.js
  6. npm run dev (ERR Child_Process)

错误

 ERROR  Failed to compile with 13 errors                                                      11:16:12 AM

These dependencies were not found:

* child_process in ./node_modules/googleapis/node_modules/google-auth-library/lib/auth/googleauth.js
* fs in ./node_modules/google-p12-pem/index.js, ./node_modules/googleapis/lib/googleapis.js and 5 others
* net in ./node_modules/forever-agent/index.js, ./node_modules/tough-cookie/lib/cookie.js and 1 other
* tls in ./node_modules/forever-agent/index.js, ./node_modules/tunnel-agent/index.js

To install them, you can run: npm install --save child_process fs net tls

问题

如何使用googleapis 构建应用程序?

【问题讨论】:

    标签: node.js google-api vue.js npm-install vue-cli


    【解决方案1】:

    您收到这些错误是因为 googleapis 库是一个 Node 库,因为它不能在客户端(浏览器)上运行,因此 Webpack 无法正确处理它。

    您可以在基于 Node 的后端(例如 Express)中使用它,但不能在客户端 Vue 应用程序中使用它 - 它可能会通过 Nuxt 与服务器端渲染的 Vue 应用程序一起使用,但不确定,但尚未尝试过。

    【讨论】:

    • 8bit,你知道Firebase Cloud Functions是否可以用作googleapis包的Node后端吗?有 examples of 3rd party APIs 使用 Cloud Functions,包括一些 Google 服务。
    • 我自己没用过,但从外观上看,似乎可以,因为它在节点上运行。文档看起来很详细,所以去试试吧。
    • 是的,Cloud Functions 允许您使用 node.js Google API 包。 Jen Person 的 excellent playlistFirebase Guide 的完美伴侣。
    • 关于如何使用 Nuxt 实现它的任何指导?我一直在寻找解决方案,但似乎无法弄清楚。
    猜你喜欢
    • 2021-01-02
    • 2021-10-14
    • 2021-03-07
    • 2021-10-28
    • 2022-09-24
    • 2023-03-20
    • 2019-12-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多