简体   繁体   English

Discord.js 'ReferenceError: require 未定义'

[英]Discord.js 'ReferenceError: require is not defined'

const client = new Discord.Client();
const config = require('./config.json');

I checked other question they contain problems regarding require(discord.js) [ye no '' between to make a string] But that is not the problem I have for some reason my terminal responds with我检查了其他问题,它们包含有关 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

For some reason I have to reinstall node again to fix it this is the 10th time this is happening also this happens right after I deploy the code with ES6 method.出于某种原因,我必须再次重新安装 node 以修复它,这是第 10 次发生这种情况,这也是在我使用 ES6 方法部署代码之后发生的。 Don't know what to do I tried reinstalling discord.js : npm i discord.js不知道该怎么办我尝试重新安装 discord.js:npm i discord.js

Same thing happened so please help me.发生了同样的事情,所以请帮助我。 Also don't give me the js is for server wide bla bla BS It worked fine like 2 minutes ago.也不要给我 js 适用于服务器范围的 bla bla BS 它在 2 分钟前工作正常。

The file containing the require statement is being treated as an ECMAScript module (which supports import and export ) instead of a CommonJS module (which supports require and module.exports ).包含require语句的文件被视为 ECMAScript 模块(支持importexport )而不是 CommonJS 模块(支持requiremodule.exports )。

You can tell because, aside from the error, the loader module is in the esm directory.您可以判断,因为除了错误之外,加载器模块位于esm目录中。

Edit your package.json file so the type field says "type": "commonjs" and not "type": "module" .编辑您的package.json文件,使type字段显示"type": "commonjs"不是"type": "module"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM