fs.readdir, glob, fast-glob all won't match any files while using Typescript

async getEvents() {
const eventPath = path.join(__dirname, "events");
fs.readdir(eventPath, async (err, files) => {
if (err) throw err;
let eventCount = 0;
for (const filePath of files) {
const event: Event<keyof ClientEvents> =
await this.importFile(filePath);
this.on(event.event, event.execute);
}
});
}
async getEvents() {
const eventPath = path.join(__dirname, "events");
fs.readdir(eventPath, async (err, files) => {
if (err) throw err;
let eventCount = 0;
for (const filePath of files) {
const event: Event<keyof ClientEvents> =
await this.importFile(filePath);
this.on(event.event, event.execute);
}
});
}
[Error: ENOENT: no such file or directory, scandir 'F:\...\dist\events'] {
errno: -4058,
code: 'ENOENT',
syscall: 'scandir',
path: 'F:\\...\\dist\\events'
}
[Error: ENOENT: no such file or directory, scandir 'F:\...\dist\events'] {
errno: -4058,
code: 'ENOENT',
syscall: 'scandir',
path: 'F:\\...\\dist\\events'
}
Directory Setup:
project root
dist/
node_modules/
src/
commands/
...
events/
interactionCreate.ts
...
structures/
Client.ts
...
index.ts
package.json
...
project root
dist/
node_modules/
src/
commands/
...
events/
interactionCreate.ts
...
structures/
Client.ts
...
index.ts
package.json
...
Client.ts is the file from the snippet. Here's my tsconfig
{
"compilerOptions": {
"lib": ["ES2021"],
"target": "ES2021",
"module": "commonjs",
"moduleResolution": "Node",
"outDir": "dist",
"sourceMap": false,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"skipDefaultLibCheck": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"strict": true
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}
{
"compilerOptions": {
"lib": ["ES2021"],
"target": "ES2021",
"module": "commonjs",
"moduleResolution": "Node",
"outDir": "dist",
"sourceMap": false,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"skipDefaultLibCheck": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"strict": true
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}
6 Replies
d.js toolkit
d.js toolkit9mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Haven
HavenOP9mo ago
@Qjuh As requested :) As you might guess, it is targeting F:\\...\\dist\\events yet not including my events dir in there. I don't know how typescript compilation is supposed to handle this Yeah, I might have mispoken, but are they supposed to be in dist??? None of the examples provided show that, and the files are certainly in the file I mean to target, and typescript should be static checking that target string right? Hold on one moment. My brain dead self messed up that code, but I believe my mistake is not the issue 1. I'll link one such in a moment. 2. I am aware, but typescript should be checking dependencies right? Isn't that how people tend to do this with import() or readsync and such? Maybe I am entirely mistaken. But the example I saw and some others show the commands and events folder within the src directory. 3. Curiously I feel I have the answer and don't for this. When I said static I meant the string with __dirname, "events" which is a mistake, but I'm sure is not the problem, just an artifact of me switching from glob back to this. But yes, thinking more of course it could not know which files in this string I want access to. Bit of a silly thought there. 4. Typescript is around at compile time, and maybe I'm wrong but does it not check template strings with constants in them?
Haven
HavenOP9mo ago
GitHub
djs-typescript-handler/src at master · limxuan/djs-typescript-handler
Contribute to limxuan/djs-typescript-handler development by creating an account on GitHub.
Haven
HavenOP9mo ago
I did yes, though there is one thing I have not tried changing, could src/**/*.ts be my issue? It is not. Though I was missing import helpers as well That does not seem to be the problem either. tsup-node src/index.ts; node dist/index.js Is there a way to get typescript to preserve file structure?
duck
duck9mo ago
you could not use tsup, a bundler
Haven
HavenOP9mo ago
Yeah, I just found that out. I thought that src/index.ts would define entry point I'm annoyed that it was that damn simple. Irritating but sometimes I remind myself how much of an amateur I am. Was recommended, not sure why, but plenty of people seemed to have it working so I assumed it had to be something else, but yes, that clearly wasn't what was needed. Fix is this. I'm silly.
Want results from more Discord servers?
Add your server