DenoDDeno
Powered by
Kas.stK
Denoβ€’2y agoβ€’
11 replies
Kas.st

Deno.readFile broken?

For some reason I can't read a file with
Deno.readFile
Deno.readFile
. I've tried relative and absolute paths. I can
cat
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
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";
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,944Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Deno CLI Broken
bbqchickenrobotBbbqchickenrobot / help
2y ago
deno_blog is broken
SkrillxSSkrillx / help
13mo ago
readFile path not found
nicetomytyukNnicetomytyuk / help
2y ago