You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I'm currently following the tutorial on the website, currently converting it to ES6 and im running into a problem.
import{readdirSync}from'node:fs';importfsfrom'node:fs/promises';import{join}from'node:path';importpathfrom'node:path';import{fileURLToPath}from'node:url';import{Client,GatewayIntentBits,Collection}from'discord.js';constclient=newClient({intents: [GatewayIntentBits.Guilds,GatewayIntentBits.GuildMembers],});const__filename=fileURLToPath(import.meta.url);const__dirname=path.dirname(__filename);constcommandsPath=join(__dirname,'commands');consteventsPath=join(__dirname,'events');constcommandFiles=readdirSync(commandsPath).filter((file)=>file.endsWith('.js'));consteventFiles=readdirSync(eventsPath).filter((file)=>file.endsWith('.js'));constconfig=JSON.parse(awaitfs.readFile('config.json'));client.commands=newCollection();for(constfileofcommandFiles){constfilePath=join(commandsPath,file);constcommand=import(filePath);//Getting error on this lineclient.commands.set(command.then.name,command);}for(constfileofeventFiles){constfilePath=join(eventsPath,file);constevent=import(filePath);if(event.once){client.once(event.name,(...args)=>event.execute(...args));}else{client.on(event.name,(...args)=>event.execute(...args));}}client.Login(config.token);
node:internal/errors:491
ErrorCaptureStackTrace(err);
^
Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
at new NodeError (node:internal/errors:400:5)
at throwIfUnsupportedURLScheme (node:internal/modules/esm/resolve:989:11)
at defaultResolve (node:internal/modules/esm/resolve:1069:3)
at nextResolve (node:internal/modules/esm/loader:161:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:834:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:415:18)
at ESMLoader.import (node:internal/modules/esm/loader:516:22)
at importModuleDynamically (node:internal/modules/esm/translators:108:35)
at importModuleDynamicallyCallback (node:internal/process/esm_loader:36:14)
at file:///C:/Users/mrash/Desktop/DiscordBot/index.js:25:19 {
code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}
I've tried googling the error and i have tried a lot of different things that don't seem to work.
Any help would be appreciated.
So the error is instead of getting file://C:/Some/Path
It is getting C:/Some/Path
Now you can see this same path if you attempt to open a file in your browser as seen below: (Z is just another drive)
My only suggestion is to concatenate file:// onto the end eg. (Try file:/// as well as that is what opera liked so it may be slightly different)
for(constfileofcommandFiles){constfilePath=join(commandsPath,file);constcommand=import("file://"+filePath);// Generates a ESM compatible file url ("file://" just means look in the fs I believe)client.commands.set(command.then.name,command);}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello, I'm currently following the tutorial on the website, currently converting it to ES6 and im running into a problem.
Beta Was this translation helpful? Give feedback.
All reactions