gpt4 book ai didi

node.js - Vue 项目和 googleapis - 不会构建 - child_process 错误

转载 作者:太空宇宙 更新时间:2023-11-03 23:23:33 24 4
gpt4 key购买 nike

目标

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

示例

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

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

  1. vue init webpack test-googleapis
  2. npm 安装
  3. npm install googleapis --savenpm install google-auth-library --save
  4. npm run dev(到目前为止,好的,应用程序构建并运行)
  5. 添加行,将 googleapis 从 '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 构建应用?

最佳答案

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

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

关于node.js - Vue 项目和 googleapis - 不会构建 - child_process 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47078811/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com