1

当我尝试加载 GoCardless SDK 并按照文档中的内容应用配置时, nodejs 会抛出以下错误:

var gocardless = require('gocardless')(gcConfig);
                                  ^

TypeError: require(...) is not a function
    at Object.<anonymous> (/Users/joe/projects/adultcms-main-site/routes/views/register.js:10:39)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at /Users/joe/projects/adultcms-main-site/node_modules/keystone/lib/core/importer.js:42:23
    at Array.forEach (native)
    at importer (/Users/joe/projects/adultcms-main-site/node_modules/keystone/lib/core/importer.js:32:26)
    at Object.<anonymous> (/Users/joe/projects/adultcms-main-site/routes/index.js:31:9)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (/Users/joe/projects/adultcms-main-site/keystone.js:58:24)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)

这是包含 SDK 的文件的样子。

var keystone = require('keystone');

var gcConfig = {
    sandbox: true,
    appId: process.env.appId,
    appSecret: process.env.appSecret,
    token: process.env.token,
    merchantId: process.env.merchantId
};
var gocardless = require('gocardless')(gcConfig);
4

1 回答 1

1

好吧,0.1.1 似乎是旧版本。该文档似乎适用于最新版本https://www.npmjs.com/package/gocardless最新版本似乎是 1.0.0-beta6。出于某种原因,尽管您似乎正在使用旧版本的模块。你能检查一下,你有什么版本的节点和 npm?您也可以尝试安装最新的模块npm install gocardless@1.0.0-beta6

于 2016-02-28T08:25:17.180 回答