即使我在異步函式中,我也會不斷收到此錯誤...
import { dirname, join } from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export async function importer(client) {
const dir = join(__dirname, "../../commands/")
const commandCategories = readdirSync(dir)
for (let cat of commandCategories) {
const commandFiles = readdirSync(join(dir, cat)).filter(files => files.endsWith(".js"));
for (const file of commandFiles) {
const command = await import(join(dir, cat, file));
client.commands.set(command.default.name, command.default);
}
}
}
有什么我想念的嗎?import我絕對需要 in中的 await 部分const command。它匯入一些命令,然后在控制臺輸出中洗掉標題中提到的錯誤。
謝謝。
uj5u.com熱心網友回復:
問題不在于importer代碼,而在于您嘗試匯入的模塊之一(并import在決議時崩潰)!
這是node 中的一個錯誤,當在dynamic 期間遇到此語法錯誤時會拋出這樣一個無用的錯誤import。
嘗試在匯入檔案名之前記錄它們,以便查看它在哪個檔案崩潰。一旦您知道哪個檔案決議失敗,請對其進行靜態匯入以進行測驗,這樣您就可以獲得一個正確的錯誤,告訴您哪一行有問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/465844.html
標籤:javascript 节点.js 不和谐 不和谐.js
