javascript - CALL_NON_FUNCTION_AS_CONSTRUCTOR(原生)NodeJS

标签 javascript node.js

此代码在其他情况下有效,但我认为文件的设置是导致问题的原因,我不确定如何解决它。这是一项契约(Contract)工作,因此我无法更改 fil 的设置,并且我不知道如何修复此错误。

我从这里调用 OAuth 模块:

var common = require('common');
var OAuth2 = require('oauth2');
var google = require('google');

exports.init = function(app) {

app.get('/oauth/google', function(req, res) {
    var gmailAuthObject =
        new OAuth2(google.clientId,
                   google.clientSecret,
                   '',
                   'https://accounts.google.com/o/oauth2/auth',
                   'https://accounts.google.com/o/oauth2/token');
    var redirectUrl = gmailAuthObject.getAuthorizeUrl(
        { redirect_uri:google.callbackRedirect,
          scope:'https://www.google.com/m8/feeds',
          response_type:'code',
          access_type:'offline' });

    res.redirect(redirectUrl);
});

app.get('/oauth/google/callback',  function(req, res) {
    var code = req.query.code;
    var content = '<script>' +
        'window.opener.SITENAME.setGoogleCode("' + code + '");' +
        'window.close();' +
        '</script>';
    res.writeHeader(200, {"Content-Type": "text/html"});
    res.end(content, 'utf-8');
});

// Other Networks...
/******************************************************************************/

};

在新的 OAuth2 上失败:CALL_NON_FUNCTION_AS_CONSTRUCTOR( native )

OAuth 模块作为每个函数的导出,例如 exports.OAuth2

我猜问题是因为它在 exports.init 内部,但我无法修复它。这里有什么想法或帮助吗?谢谢!

最佳答案

如果您使用this module ,看来你应该这样做(在你提供的代码的第二行):

var OAuth2 = require("oauth2").OAuth2;

关于javascript - CALL_NON_FUNCTION_AS_CONSTRUCTOR(原生)NodeJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9279401/

相关文章:

javascript - 如果最新关闭,则折叠在第一个

使用带有特殊字符的密码的 Javascript Ajax 调用

javascript - 处理单击并悬停在同一元素上并保持弹出模式打开,直到弹出模式悬停在上方

java - 在 Node.js 中使用 base64 rsa 公钥进行加密

javascript - 可调差异算法

javascript - 更改 route 标记的默认图标

javascript - 当我在 jsp 和 css 文件中复制我的 html 文件时,我的页面设计发生了变化

javascript - MetaMask - RPC 错误 : Error: [ethjs-query] while formatting outputs from RPC

javascript - 如何在 firebase 中向用户添加自定义配置文件详细信息?

javascript - 生成文件的可下载链接并自动启动下载