Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Run/Debug As" > "Node program" for Typescript file may launch wrong Javascript file #1366

Closed
AndrewFerr opened this issue Oct 14, 2023 · 6 comments

Comments

@AndrewFerr
Copy link
Member

Depending on the layout of project files & tsconfig.json, trying to run a Typescript file may fail to find the correct path of that file's associated Javascript file, and thus fail to run the file.

For example, excluding node_modules and lockfiles, I have a project directory of:

.
├── lib
│   ├── main.js
│   └── main.js.map
├── package.json
├── src
│   └── main.ts
└── tsconfig.json

and a tsconfig.json of

{
	"extends": "@tsconfig/node16/tsconfig.json",
	"compilerOptions": {
		"sourceMap": true,
		"outDir": "lib",
		"rootDir": "src",
		"lib": ["dom", "es2020"]
	}
}

When trying to run ./src/main.ts, WWD should run ./lib/main.js, but it instead launches ./lib/src/main.js, which doesn't exist.

It seems that WWD constructs the path of the Javascript file to run as

jsToRun=${project-directory}/${outDir}/${project-relative-path-to-ts-file/.ts/.js}

but it should be

trueDir=${project-relative-path-to-ts-file/${rootDir}/${outDir}}
jsToRun=${project-directory}/${trueDir/.ts/.js}}

where I've used Bash to illustrate the path construction.

@mickaelistria
Copy link
Contributor

Would you be able to provide a PR illustrating this in a test case and fixing it?
Note that in microsoft/vscode-js-debug#1838 , the maintainers of vscode-js-debug mention that the ts -> js resolution should be handled on the adapter end, so we could in theory pass directly the path to the .ts file. But I didn't manage to get it to work earlier.
So if you're willing to put workforce on this topic, instead of fixing how Wild Web Developer resolves the path, it could be more interesting to make the DAP resolution work and drop the resolution in Wild Web Developer.

@AndrewFerr
Copy link
Member Author

Sounds like a plan. I'll give it a try.

@mickaelistria
Copy link
Contributor

Submitted #1368 as a quick-fix, but that doesn't mean we can't do better by using the debug adapter feature directly ;)

@wesleybl
Copy link

When trying to run ./src/main.ts, WWD should run ./lib/main.js, but it instead launches ./lib/src/main.js, which doesn't exist.

@AndrewFerr @mickaelistria WWD should run ./lib/main.js, but the debug must be in ./src/main.ts, correct? I have a case where the source code is js files and then webpack generates a large build/server.js file. When I put the breaking point in the source file, the debugged file is build/server.js instead of the source file. I'll open an issue about this later.

@AndrewFerr
Copy link
Member Author

@wesleybl Yes, the debug should be in the TS file, or in your case, the source JS file instead of the Webpack-generated JS file.

Did you enable source maps in your Webpack config? If so, then perhaps the debug adapter is aware of only TS->JS mappings.

@AndrewFerr
Copy link
Member Author

Submitted #1368 as a quick-fix, but that doesn't mean we can't do better by using the debug adapter feature directly ;)

Downloaded the snapshot & verified that the quick fix works, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants