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

时间:2017-11-02 15:20:16

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

目标

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

实施例

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

要创建此示例,我只需:

  1. vue init webpack test-googleapis
  2. npm install
  3. npm install googleapis --savenpm install google-auth-library --save
  4. npm run dev(到目前为止,还可以,app构建并运行)
  5. 将行import googleapis from 'googleapis'添加到main.js
  6. npm run dev(ERR Child_Process
  7. 错误

     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构建应用程序?

1 个答案:

答案 0 :(得分:1)

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

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

相关问题