Vue项目和googleapis – 不会生成 – child_process错误

目标

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

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

为了创build这个例子,我简单地:

  1. vue init webpack test-googleapis
  2. npm install
  3. npm install googleapis --savenpm install google-auth-library --save
  4. npm run dev (到目前为止,没关系,应用程序build立和运行)
  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构build应用程序?

你得到这些错误,因为googleapis库是一个Node库,因为它不能在客户端(浏览器)工作,所以Webpack无法正确处理它。

您可以在基于Node的后端(例如Express)中使用它,但不能在客户端Vue应用程序中使用它 – 它可能通过Nuxt与服务器端呈现的Vue应用程序一起工作,不确定,但没有尝试过。