title: How to fix Must use import to load ES Module discord.js
body: <p>I am working on a bot i made a roast command i am getting this error</p>
  <pre><code>internal/modules/cjs/loader.js:1089
        throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
        ^
  
  Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\Users\acer\Documents\test\node_modules\node-fetch\src\index.js
  require() of ES modules is not supported.
  require() of C:\Users\acer\Documents\test\node_modules\node-fetch\src\index.js from C:\Users\acer\Documents\test\commands\roast.js is an ES module file as it is a .js file whose nearest parent package.json contains &quot;type&quot;: &quot;module&quot; which defines all .js files in that package scope as ES modules.
  Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove &quot;type&quot;: &quot;module&quot; from C:\Users\acer\Documents\test\node_modules\node-fetch\package.json.
  
  ←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1089:13)←[39m
  ←[90m    at Module.load (internal/modules/cjs/loader.js:937:32)←[39m
  ←[90m    at Function.Module._load (internal/modules/cjs/loader.js:778:12)←[39m
  ←[90m    at Module.require (internal/modules/cjs/loader.js:961:19)←[39m
  ←[90m    at require (internal/modules/cjs/helpers.js:92:18)←[39m
      at Object.&lt;anonymous&gt; (C:\Users\acer\Documents\test\commands\roast.js:3:15)
  ←[90m    at Module._compile (internal/modules/cjs/loader.js:1072:14)←[39m
  ←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)←[39m
  ←[90m    at Module.load (internal/modules/cjs/loader.js:937:32)←[39m
  ←[90m    at Function.Module._load (internal/modules/cjs/loader.js:778:12)←[39m {
    code: ←[32m'ERR_REQUIRE_ESM'←[39m
  </code></pre>
  <p>this is my roast.js</p>
  <pre><code>const random = require(&quot;something-random-on-discord&quot;).Random
  const oneLinerJoke = require('one-liner-joke');
  const fetch = require('node-fetch')
  const Discord = require('discord.js')
  module.exports = {
      name : 'roast',
      description : 'roasts a user',
      
    async execute(message, args){
         if (!args[0]) return message.channel.send('Invalid Format')
         const mentionedMember = message.guild.mentions.member.first();
         if (!mentionedMember) return message.channel.send('User not found')
          let msg = await message.channel.send('Setting a roast...')
  
          fetch('http://evilinsult.com/generate_insult.php?lang=en&amp;type=json')
              .then(res =&gt; res.json())
              .then(json =&gt; {
                  message.channel.send(json.insult)
              });
      }
  
  }
  </code></pre>
  <p>this is my main.js</p>
  <pre><code>// Import the discord.js module
  const Discord = require('discord.js');
  const fs = require('fs');
  // Create an instance of a Discord client
  const client = new Discord.Client();
  client.commands = new Discord.Collection();
  const commandFiles = fs.readdirSync('./commands').filter(file =&gt; file.endsWith('.js'));
  const prefix = &quot;$&quot;
  
  /**
   * The ready event is vital, it means that only _after_ this will your bot start reacting to information
   * received from Discord
   */
  client.on('ready', () =&gt; {
    console.log('I am ready!');
  });
   
  client.on('message', message =&gt; {
    if (!message.content.startsWith(prefix) || message.author.bot) return;
  
    const args = message.content.slice(prefix.length).trim().split(/ +/);
    const command = args.shift().toLowerCase();
  
  
    if(command === 'pingg'){
      client.commands.get('pingg').execute(message, args);
    }
    if(command === 'roast'){
      client.commands.get('roast').execute(message, args);
    }
  
  
  
  
    if (!client.commands.has(command)) return;
  
    try {
        client.commands.get(command).execute(message, args);
    } catch (error) {
        console.error(error);
        message.reply('there was an error trying to execute that command!');
    }
  });
   
  
  commandFiles.forEach(file =&gt; {
    const command = file.split(/.js$/)[0];
    client.commands.set(command, require(`./commands/${file}`));
  });
  
  
  
  client.login('censored');
  </code></pre>