0

I have the following configuration in my launch.json file

        {
            "type": "node",
            "request": "launch",
            "name": "Server - Current File",
            "program": "${file}",
            "cwd": "${workspaceFolder}/server",
            "runtimeExecutable": "tsx",
            "outputCapture": "std",
            "env": {
                "NODE_ENV": "development"
            }
        },

I am using it to run files from my src folder using tsx without running a full build. The problem is if a build folder exist it will run the file from the build folder instead of running the src folder version.

└── server/
    ├── src/
    │   └── file.ts
    └── build/
        └── file.js

If my open file is the src/file.ts, running the following launch.json config will run the build/file.js instead. But if I delete the build folder, then it will run the src/file.ts correctly.

5
  • doesn't this use the file in the currently active/focused editor tab? just focus the one you want. Commented Nov 10 at 11:43
  • @starball that's the exact issue, I am focused on the file from src folder and it still runs the one in build folder Commented Nov 10 at 12:21
  • how do you know it's running the one from the build folder? can you give us readers some hard facts to help us see what you're seeing? Commented Nov 10 at 12:35
  • @starball when the program starts from launch.json the first line logs the command that is running, and it literally says build/file.js Commented Nov 10 at 12:43
  • @eliezra236 do you have the rest of the launch.json by chance? You could hardcode the path as well as a troubleshooting step! I wonder if the issue comes from either another portion of your launch JSON or the definition of ${file} instead of ${workspaceFolder}. If the hardcoded path work, you may try something along the lines of "program": "${workspaceFolder}/server/src/file.tsx" Commented Nov 10 at 20:12

1 Answer 1

0

Actually node resolves .js modules first like if .js exist use it, you can try using "runtimeArgs": ["--no-file-system-resolution"] in your launch.json:

{  
    "type": "node",  
    "request": "launch",  
    "name": "Server - Current File",  
    "program": "${file}",  
    "cwd": "${workspaceFolder}/server",  
    "runtimeExecutable": "tsx",  
    "runtimeArgs": \["--no-file-system-resolution"\],  
    "env": {  
        "NODE_ENV": "development"  
    }  
}
Sign up to request clarification or add additional context in comments.

2 Comments

The reference to build folder happen from VSCode itself, so adding this arg will cause tsx --no-file-system-resolution ./build/file.js, so it will still refer to the build folder
you tried this solution? from Henrique Donati : "program": "${workspaceFolder}/server/src/file.tsx"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.