Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find node module 'node:fs' when using js and trying to deploy to my personal server that runs linux

Error: Cannot find module 'node:fs'
   at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
   at Function.Module._load (internal/modules/cjs/loader.js:562:25)
   at Module.require (internal/modules/cjs/loader.js:692:17)
   at require (internal/modules/cjs/helpers.js:25:18)
   at Object.<anonymous> (/home/doge/atlas/db-bot/Index.js:1:12)
   at Module._compile (internal/modules/cjs/loader.js:778:30)
   at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
   at Module.load (internal/modules/cjs/loader.js:653:32)
   at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
   at Function.Module._load (internal/modules/cjs/loader.js:585:3)

My package.JSON file:

{
  "name": "atlas-db",
  "version": "1.0.0",
  "description": "[REDACTED]",
  "main": "Index.js",
  "scripts": {
    "test": "none"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/[REDACTED]/db-bot.git"
  },
  "keywords": [
    "bot"
  ],
  "author": "[REDACTED]",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/[REDACTED]/db-bot/issues"
  },
  "homepage": "https://github.com/[REDACTED]/db-bot#readme",
  "dependencies": {
    "@discordjs/builders": "^0.13.0",
    "@discordjs/rest": "^0.4.1",
    "@types/node": "^17.0.35",
    "axios": "^0.27.2",
    "discord-api-types": "^0.32.1"
  }
}

I've ran npm i

I've tried everything. It works on Windows but not Linux, I have no clue why.

Just saying that this happens in every file that requires "node:x"

Its really odd.

My index:

const fs = require('node:fs');
const { Client, Collection, Intents } = require('discord.js');
const { token } = require('./config.json');

const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
        const command = require(`./commands/${file}`);
        client.commands.set(command.data.name, command);
}

client.once('ready', () => {
        console.log('Ready!');
});

client.on('interactionCreate', async interaction => {
        if (!interaction.isCommand()) return;

        const command = client.commands.get(interaction.commandName);

        if (!command) return;

        try {
                await command.execute(interaction);
        } catch (error) {
                console.error(error);
                await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
        }
});

client.login(token);
like image 272
Doge Avatar asked Dec 07 '25 08:12

Doge


1 Answers

I believe you're reading nodejs v18 docs, while not having nodejs v18 installed on your system. Since node:fs is introduced in v18, fs is the package for versions previous than that. Either upgrade nodejs to v18 or else simply rename node:fs to fs.

like image 181
Ren Hiyama Avatar answered Dec 08 '25 21:12

Ren Hiyama



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!