Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.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 如何删除TypeError:";x";这不是一个函数吗?_Node.js_Node Modules - Fatal编程技术网

Node.js 如何删除TypeError:";x";这不是一个函数吗?

Node.js 如何删除TypeError:";x";这不是一个函数吗?,node.js,node-modules,Node.js,Node Modules,我正在尝试学习如何创建一个discord bot,并从这个名为Ergast()的API中提取数据。我发现了这个npm(),它使用NodeJS实现从ergastapi获取F1数据的历史记录。对不起,我的措辞不好,我还在努力学习行话 我按照npm文档中的说明进行安装,并尝试使用该示例从API获取数据。然而,当我在index.js中运行代码时,我得到了错误“TypeError:“x”不是一个函数”。当我进入node_modules“f1 stats”文件夹并运行main.js中的代码时,我确实得到了正

我正在尝试学习如何创建一个discord bot,并从这个名为Ergast()的API中提取数据。我发现了这个npm(),它使用NodeJS实现从ergastapi获取F1数据的历史记录。对不起,我的措辞不好,我还在努力学习行话

我按照npm文档中的说明进行安装,并尝试使用该示例从API获取数据。然而,当我在index.js中运行代码时,我得到了错误“TypeError:“x”不是一个函数”。当我进入node_modules“f1 stats”文件夹并运行main.js中的代码时,我确实得到了正确的结果

index.js:

const client = new Discord.Client(); //This will be our client 
const { prefix, token } = require('./config.json');//const PREFIX = '!';
const f1s = require('f1-stats');

//module.exports.f1s = f1s; //Still causes the TypeError

f1s("2008 drivers", (res) => {
    console.log(res);
});
f1s("2008 drivers", (res) => {
^

TypeError: f1s is not a function
    at Object.<anonymous> (C:\Users\RyanPC\Documents\DiscordBot\index.js:8:1)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
我在index.js中得到的错误消息:

f1s("2008 drivers", (res) => {
^

TypeError: f1s is not a function
    at Object.<anonymous> (C:\Users\RyanPC\Documents\DiscordBot\index.js:8:1)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
当我在node_modules/f1 stats/main.js中运行它时:

const f1s = require("./f1-stats"); // "./" is used because module is located in the same folder as the Node.js file

f1s("2008 drivers", (res) => {
    console.log(res);
});
{ MRData:
   { xmlns: 'http://ergast.com/mrd/1.4',
     series: 'f1',
     url: 'http://ergast.com/api/f1/2008/drivers.json',
     limit: '30',
     offset: '0',
     total: '22',
     DriverTable: { season: '2008', Drivers: [Array] } } }

因为
f1 stats
不导出任何东西,所以在导入时。它是空的。需要导入的正确文件是
f1 stats/f1 stats

const f1s = require('f1-stats/f1-stats');

尝试正确导入f1s,您会遇到错误,因为您没有正确导入函数,换句话说…检查从您尝试导入的内容导出的内容…希望它能解决问题