[英]Discord.js 'ReferenceError: require is not defined'
const client = new Discord.Client();
const config = require('./config.json');
我檢查了其他問題,它們包含有關 require(discord.js) [ye no '' between to make a string] 的問題,但這不是我遇到的問題,出於某種原因,我的終端響應為
const Discord = require('discord.js');
^
ReferenceError: require is not defined
at file:///C:/Users/tee-hee/Documents/Bots/Darkness/main.js:1:17
at ModuleJob.run (internal/modules/esm/module_job.js:140:23)
at async Loader.import (internal/modules/esm/loader.js:165:24)
at async Object.loadESM (internal/process/esm_loader.js:68:5
出於某種原因,我必須再次重新安裝 node 以修復它,這是第 10 次發生這種情況,這也是在我使用 ES6 方法部署代碼之后發生的。 不知道該怎么辦我嘗試重新安裝 discord.js:npm i discord.js
發生了同樣的事情,所以請幫助我。 也不要給我 js 適用於服務器范圍的 bla bla BS 它在 2 分鍾前工作正常。
包含require
語句的文件被視為 ECMAScript 模塊(支持import
和export
)而不是 CommonJS 模塊(支持require
和module.exports
)。
您可以判斷,因為除了錯誤之外,加載器模塊位於esm
目錄中。
編輯您的package.json
文件,使type
字段顯示"type": "commonjs"
而不是"type": "module"
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.