gpt4 book ai didi

javascript - TypeError : path. 连接不是函数

转载 作者:行者123 更新时间:2023-12-05 00:27:48 26 4
gpt4 key购买 nike

如果我拿走我用以下包装代码的函数,我发布的代码就可以工作:

watcher.on('add', function (path) { 
});


但是如果运行下面的代码。我确实在 path.join 不是函数的情况下收到此错误。
正如所见,我想在添加文件时一直运行 watcher.on 中的代码。当我添加文件时,代码会使用react,但我总是收到以下错误。
我是否设置了 watcher.on 代码错误或导致错误的原因?

文件 C:\myproject\instances\b53pd4574z8pe9x793go\New Text Document.txt 已添加
(node:14360) UnhandledPromiseRejectionWarning: TypeError: path.join is not a function


完整代码:

'use strict';
const ccxt = require('ccxt');
const fs = require('fs');
const path = require('path');
var chokidar = require('chokidar');
var watcher = chokidar.watch('C:/myproject/instances/b53pd4574z8pe9x793go', { ignored: /^\./, persistent: true });


var i;
const exchangename = "binance";
const exchange = new ccxt.binance({
'enableRateLimit': false
});



watcher.on('add', function (path) {
(async () => {
console.log('File', path, 'has been added')
const start = Date.now()


var orderbookPromises = []
var symbols = ['ETH/BTC']
for (i = 0; i < symbols.length; i++) {

const symbol = symbols[i]

try {
let tickerProcessing = new Promise(async (resolve) => {
const orderbook = await exchange.fetchOrderBook(symbol, 5)

const exchangename2 = exchangename + '#' + symbol.replace("/", "")
const dumpFile = path.join(__dirname, 'orderbooks', `${exchangename2}Orderbook.txt`)
await fs.promises.writeFile(dumpFile, JSON.stringify(orderbook))
resolve()
})
orderbookPromises.push(tickerProcessing)

} catch (e) {
console.error(e)
}
}

// wait for all of them to execute or fail
await Promise.all(orderbookPromises)


const end = Date.now()
console.log(`Done in ${(end - start) / 1000} seconds`)
})()
});

最佳答案

我认为,这是因为您将“路径”作为参数发送,同时尝试从“路径”调用 join()。重命名“函数(路径)”中的输入参数,我认为这会有所帮助。

关于javascript - TypeError : path. 连接不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54992393/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com