-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot import all the files from a folder. #7907
Comments
@bartlomieju feels like it is related to #7549 and #7672 |
Fixed in #7911 |
It still doesn't work :/ Check file:///C:/Users/Pierre/WebstormProjects/deno/tsc-bot/mod.ts
Successfully loaded 'CompileCommand' command !
Check file:///C:/Users/Pierre/WebstormProjects/deno/tsc-bot/src/commands/ReloadCommand.ts
error: Uncaught ReferenceError: default is not defined
const cmd: any = commandClass.default;
^
at mod.ts:27:33 The two commands that I have are exported the same way so it shouldn't say this 🤔 |
Okay no problem, I'll wait. |
@Ayfri could you provide a reproduction steps that I could run locally to test it on your project? |
@bartlomieju I pushed the code into this repo This project is very experimental so it contains bad code ¯_(ツ)_/¯ |
@Ayfri FYI I've fixed TLA implementation, but there's still a problem with your code - you've got circular import originating from dynamic import - when you import |
Yes, this code was just a test and wasn't defined to be public so I will restructure everything so it will be clean and functional ^^ Thanks for fixing that, I'm waiting for the release! |
Still not working in 1.5.1, still getting this in console Check file:///C:/Users/Pierre/WebstormProjects/deno/tsc-bot/mod.ts
Check file:///C:/Users/Pierre/WebstormProjects/deno/tsc-bot/src/commands/CompileCommand.ts
Successfully loaded 'CompileCommand' command !
Check file:///C:/Users/Pierre/WebstormProjects/deno/tsc-bot/src/commands/ReloadCommand.ts |
It isn't clear to me what isn't working. Could you provide a clearer picture of what you expect to happen and what isn't happening in 1.5.1, hopefully with a full example that could be run? |
I have a directory But what I am getting is the fetch, then the import of the first file, then nothing. You can see the code here. |
This comment still stands - when you import |
Oh... If I move the fetching and import part from the |
@Ayfri yes that should work, try registering commands in a separate file. |
// @filename: mod.ts
import {loadCommands} from './loadCommands.ts';
[...]
export const commands = new Collection<string, Command>();
const cmdDir: Iterable<Deno.DirEntry> = Deno.readDirSync(Deno.realPathSync(configs.commandsFolder));
await loadCommands(cmdDir, commands);
console.log(commands); // @filename: loadCommands
import {configs} from './configs.ts';
import {Collection, SEP} from './deps.ts';
import type Command from './src/classes/Command.ts';
export async function loadCommands(cmdDir: Iterable<Deno.DirEntry>, commands: Collection<string, Command>): Promise<void> {
for (let command of [...cmdDir]) {
if (command.isFile && command.name.endsWith('.ts')) {
const path: string = Deno.realPathSync(configs.commandsFolder + SEP + command.name);
const commandClass: any = await import(`file://${path}`);
const cmd: any = commandClass.default;
if (!cmd) {
console.warn(`Could not load '${command.name}' command !`);
continue;
}
commands.set(cmd.name, new cmd());
console.log(`Successfully loaded '${cmd.name}' command !`);
}
}
} This has the same behavior than before. 🤔 |
And I don't understand why does the |
@Ayfri You do import it - https://github.com/Ayfri/tsc/blob/master/src/commands/ReloadCommand.ts#L3. You shouldn't move the loadCommands function into a separate file - you should move the |
Oooh, I understand now, I fixed it and it works now, thank you! |
Hi!
I'm making a Discord bot with dynamic commands (automatic loading/reloading).
It's not my first Discord bot but all previous was made using node.js and
require()
to do this dynamically.But here it doesn't work using
await import()
:/Here is my code :
I have two commands, named
CompileCommand.ts
andReloadCommand.ts
, this is the code of the commandreload
:So when I launch all this, it loads the first command but stops at the second for no reason, not sending any error (it was sending one in deno 1.4.4 and now I am in 1.4.5).
There are the logs :
(
tsc-bot/mod.ts
is the file where there is the command handler)I don't know what it is doing, why it does that and I want some help ^^'
The text was updated successfully, but these errors were encountered: