Kas.st
Kas.st
Explore posts from servers
DDeno
Created by Kas.st on 10/18/2024 in #help
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:
...
async function fixImport(
file: string,
line: number,
char: number,
broken: string
) {
const fixed = broken + ".ts";

// open the file and replace 'broken' with 'fixed'
const relative = file.replace(Deno.cwd(), ".");

const decoder = new TextDecoder();
const bytes = await Deno.readFile(relative);
const content = decoder.decode(bytes);

...
}
...
...
async function fixImport(
file: string,
line: number,
char: number,
broken: string
) {
const fixed = broken + ".ts";

// open the file and replace 'broken' with 'fixed'
const relative = file.replace(Deno.cwd(), ".");

const decoder = new TextDecoder();
const bytes = await Deno.readFile(relative);
const content = decoder.decode(bytes);

...
}
...
and the output including cat:
root@2da2d8303d16:/secretproject/frontend/datalayer# deno run fix:imports
Task fix:imports deno run --allow-read --allow-write --allow-env --allow-net --allow-run fix.imports.ts
🔍 found broken import "/secretproject/frontend/datalayer/datalayer/core/rest/schemas.gen" in "/secretproject/frontend/datalayer/datalayer/core/rest/index.ts" (2:15)
error: Uncaught (in promise) NotFound: No such file or directory (os error 2): readfile './datalayer/core/rest/index.ts'
const bytes = await Deno.readFile(relative);
^
at Object.readFile (ext:deno_fs/30_fs.js:747:24)
at fixImport (file:///secretproject/frontend/datalayer/fix.imports.ts:13:28)
at file:///secretproject/frontend/datalayer/fix.imports.ts:55:13
at eventLoopTick (ext:core/01_core.js:175:7)
root@2da2d8303d16:/secretproject/frontend/datalayer# cat ./datalayer/core/rest/index.ts
// This file is auto-generated by @hey-api/openapi-ts
export * from "./schemas.gen";
export * from "./services.gen";
export * from "./types.gen";
root@2da2d8303d16:/secretproject/frontend/datalayer# deno run fix:imports
Task fix:imports deno run --allow-read --allow-write --allow-env --allow-net --allow-run fix.imports.ts
🔍 found broken import "/secretproject/frontend/datalayer/datalayer/core/rest/schemas.gen" in "/secretproject/frontend/datalayer/datalayer/core/rest/index.ts" (2:15)
error: Uncaught (in promise) NotFound: No such file or directory (os error 2): readfile './datalayer/core/rest/index.ts'
const bytes = await Deno.readFile(relative);
^
at Object.readFile (ext:deno_fs/30_fs.js:747:24)
at fixImport (file:///secretproject/frontend/datalayer/fix.imports.ts:13:28)
at file:///secretproject/frontend/datalayer/fix.imports.ts:55:13
at eventLoopTick (ext:core/01_core.js:175:7)
root@2da2d8303d16:/secretproject/frontend/datalayer# cat ./datalayer/core/rest/index.ts
// This file is auto-generated by @hey-api/openapi-ts
export * from "./schemas.gen";
export * from "./services.gen";
export * from "./types.gen";
12 replies