Deno.readFile broken?
For some reason I can't read a file with
Deno.readFile
. I've tried relative and absolute paths. I can cat
the file without issues.
Here's the relevant snippet:
and the output including cat
:
6 Replies
Looks like the filepth is wrong. It's looking for a file at:
Is this the correct path?
I find that for finding path issues it often helps to log out
Deno.cwd()
to see if my assumptions with relative paths is correct. You can also use import.meta.dirname
to construct absolute paths from the current fileIf I read the absolute path it fails aswell, I can
cat
it without issuesCan't reproduce that on my end, regardless of passing relative or absolute paths. What I tried:
1. Create a new project with
deno init
2. Replace contents of main.ts
with
3. Run deno run -A main.ts
hmm I've checked that
Deno.cwd === import.meta.dirname
and it's the same
here's the full scriptThanks for sharing. I assume the file you want to read is relative to that script at
./datalayer/mod.ts
?
Ah I see the issue. Your regex doesn't account for ansi escape codes. This is the file path I'm getting from the regex:
Unrelated: It looks like the goal of the script is to find and fix missing extensions in import paths. We have an unstable lint rule for that which might interest you:
It can also add the missing extensions by running:
oh, I saw the unstable flag but didn't know it's autofixable š
thanks for helping!