Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js NodeJS-googleapi模块-[TypeError:无法读取未定义的属性';prototype']_Node.js_Azure Mobile Services_Google Api Nodejs Client - Fatal编程技术网

Node.js NodeJS-googleapi模块-[TypeError:无法读取未定义的属性';prototype']

Node.js NodeJS-googleapi模块-[TypeError:无法读取未定义的属性';prototype'],node.js,azure-mobile-services,google-api-nodejs-client,Node.js,Azure Mobile Services,Google Api Nodejs Client,我将nodejs模块“googleapis”(npm install googleapis)安装到一个Azure移动服务实例中,我想用我在这里找到的一些示例代码进行快速测试。尝试在google drive中创建文本文件的代码示例后,我在控制台中收到以下错误消息: [TypeError: Cannot read property 'prototype' of undefined] 错误发生在当前版本的google api nodejs client/api/index.js()的第40行: 调试

我将nodejs模块“googleapis”(
npm install googleapis
)安装到一个Azure移动服务实例中,我想用我在这里找到的一些示例代码进行快速测试。尝试在google drive中创建文本文件的代码示例后,我在控制台中收到以下错误消息:

[TypeError: Cannot read property 'prototype' of undefined]
错误发生在当前版本的google api nodejs client/api/index.js()的第40行:

调试时,我可以看到上述方法中使用的路径如下所示:

D:\home\site\wwwroot\App_Data\config\scripts\node_modules\googleapis\apis\drive\v2
我已验证路径是否正确

以下是我尝试运行的代码:

var google = require('googleapis');

var OAuth2Client = google.auth.OAuth2;
var CLIENT_ID = 'xxxx';
var CLIENT_SECRET = 'xxxxxx';
var REDIRECT_URL = 'xxxxx';
var oauth2Client = new OAuth2Client(CLIENT_ID, CLIENT_SECRET, REDIRECT_URL);
oauth2Client.setCredentials({
access_token: identities.google.accessToken
});

var drive = google.drive({ version: 'v2', auth: oauth2Client });

drive.files.insert({
  resource: {
    title: 'Test',
    mimeType: 'text/plain'
  },
  media: {
    mimeType: 'text/plain',
    body: 'Hello World'
  }
}, function(err, response) {
console.log('error:', err, 'inserted:', response.id);
});
问题的根源是什么

以下是错误堆栈跟踪:

TypeError: Cannot read property 'prototype' of undefined at Object.<anonymous> 
(D:\home\site\wwwroot\App_Data\config\scripts\node_modules\googleapis\node_modules\multipart-stream\node_modules\sandwich-stream\lib\sandwich-stream.js:24:50) 
    at Module._compile (module.js:449:26) 
    at Object.Module._extensions..js (module.js:467:10) 
    at Module.load (module.js:356:32) 
    at Function.Module._load (module.js:312:12) 
    at Module.require (module.js:362:17) 
    at require (module.js:378:17) 
    at Object.<anonymous> (D:\home\site\wwwroot\App_Data\config\scripts\node_modules\googleapis\node_modules\multipart-stream\index.js:1:78) 
    at Module._compile (module.js:449:26) 
    at Object.Module._extensions..js (module.js:467:10)
nodejs版本为:

Node version: v0.8.28

我的猜测是Azure移动服务正在使用_dirname做一些奇怪的事情,这使得文件路径无法正确解析。你能检查一下运行这个的日志吗?实际错误应该是console.log'd,从这一行开始:

路径如下:d:\home\site\wwwroot\App\u Data\config\scripts\node\u modules\googleapis\api/drive/v2,index.js的第45行返回的错误是[TypeError:Cannot read property'prototype'of undefined],我确认路径正确。D:\home\site\wwwroot\App\u Data\config\scripts\node\u modules\googleapis\api/drive/‌​v2.js是文件在服务器上的位置。我认为问题是由Win32系统上的混合路径分隔符引起的。我刚刚提交了一份报告,希望能解决这个问题。如果可以,请尝试修改项目中的API/index.js,使其包含PR中引入的更改,并让我们知道这是否适用于您。@RobertRossmann不幸的是,我昨天尝试了此方法,但没有解决我的问题。引发错误的行是
var Endpoint=require('D:\home\site\wwwroot\App\u Data\config\scripts\node\u modules\googleapis\api\drive\v2')
。[TypeError:无法读取未定义的属性'prototype'。我还尝试将.js扩展添加到路径中,并使用fs.existsSync()方法验证了路径是否正确。很抱歉,google api nodejs客户端的1.x版本仅支持节点0.10.x。您可以在此处的.travis.yml文件中看到:
SandwichStream.prototype = Object.create(Readable.prototype, {
  constructor: SandwichStream
});
Node version: v0.8.28