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
TTCTheo's Typesafe Cult
Created by Kas.st on 8/29/2024 in #questions
Debugging node_modules in VS Code of a Next.js app
I'm trying to set breakpoints inside an installed package, but the breakpoints are unbound, since the dependencies are bundled with webpack. I'm using the following lauch.json taken from https://nextjs.org/docs/pages/building-your-application/configuring/debugging#debugging-with-vs-code
{
"version": "0.2.0",
"configurations": [
{
"name": "Next.js: debug server-side",
"type": "node-terminal",
"request": "launch",
"command": "npm run dev"
},
{
"name": "Next.js: debug client-side",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000"
},
{
"name": "Next.js: debug full stack",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/.bin/next",
"runtimeArgs": ["--inspect"],
"skipFiles": ["<node_internals>/**"],
"serverReadyAction": {
"action": "debugWithEdge",
"killOnServerStop": true,
"pattern": "- Local:.+(https?://.+)",
"uriFormat": "%s",
"webRoot": "${workspaceFolder}"
}
}
]
}
{
"version": "0.2.0",
"configurations": [
{
"name": "Next.js: debug server-side",
"type": "node-terminal",
"request": "launch",
"command": "npm run dev"
},
{
"name": "Next.js: debug client-side",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000"
},
{
"name": "Next.js: debug full stack",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/.bin/next",
"runtimeArgs": ["--inspect"],
"skipFiles": ["<node_internals>/**"],
"serverReadyAction": {
"action": "debugWithEdge",
"killOnServerStop": true,
"pattern": "- Local:.+(https?://.+)",
"uriFormat": "%s",
"webRoot": "${workspaceFolder}"
}
}
]
}
Does anyone know how I can setup proper debugging of not just my code but also the node modules?
2 replies