npm 使用js并尝试部署到运行linux的个人服务器时找不到节点模块“node:fs”

3pmvbmvn  于 2023-08-06  发布在  Linux
关注(0)|答案(2)|浏览(139)
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)

字符串
我的package.JSON文件:

{
  "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"
  }
}


我运行了npm i
我什么都试过了它可以在Windows上工作,但不能在Linux上工作,我不知道为什么。
只是说这会发生在每个需要“node:x”的文件中
真的很奇怪。
我的指数:

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);

rjee0c15

rjee0c151#

我相信你正在阅读nodejs v18文档,而你的系统上还没有安装nodejs v18。由于node:fs是在v18中引入的,因此fs是之前版本的包。将nodejs升级到v18,或者将node:fs重命名为fs

sigwle7e

sigwle7e2#

更新到节点lts全局为我工作。

相关问题