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

Not supported to run in the VSCode extension #624

Open
4 of 6 tasks
sxzz opened this issue Jul 29, 2024 · 9 comments
Open
4 of 6 tasks

Not supported to run in the VSCode extension #624

sxzz opened this issue Jul 29, 2024 · 9 comments
Labels
blocked bug Something isn't working

Comments

@sxzz
Copy link

sxzz commented Jul 29, 2024

Acknowledgements

  • I read the documentation and searched existing issues to avoid duplicates
  • I understand this is a bug tracker and anything other than a proven bug will be closed
  • I understand this is a free project and relies on community contributions
  • I read and understood the Contribution guide

Minimal reproduction URL

https://github.com/sxzz/tsx-vscode-ext

Problem & expected behavior (under 200 words)

Run pnpm lint; it works. However, in the VSCode environment, the ESLint extension shows an error.

[Error - 10:20:51 AM] Request textDocument/diagnostic failed.
  Message: Request textDocument/diagnostic failed with message: Cannot read properties of undefined (reading 'size')
  Code: -32603 

The full error stack:

TypeError [Error] [TransformError]: Cannot read properties of undefined (reading 'size')
    at normalizeSpawnArguments (node:child_process:726:34)
    at Object.spawn (node:child_process:792:13)
    at ensureServiceIsRunning (/path/tsx-vscode-ext/node_modules/.pnpm/esbuild@0.21.5/node_modules/esbuild/lib/main.js:1975:29)
    at transform (/path/tsx-vscode-ext/node_modules/.pnpm/esbuild@0.21.5/node_modules/esbuild/lib/main.js:1875:37)
    at file:///path/tsx-vscode-ext/node_modules/.pnpm/[email protected]/node_modules/tsx/dist/index-DeKCL_WS.mjs:16:2654
    at applyTransformers (file:///path/tsx-vscode-ext/node_modules/.pnpm/[email protected]/node_modules/tsx/dist/index-DeKCL_WS.mjs:16:1266)
    at transform (file:///path/tsx-vscode-ext/node_modules/.pnpm/[email protected]/node_modules/tsx/dist/index-DeKCL_WS.mjs:16:2601)
    at load (file:///path/tsx-vscode-ext/node_modules/.pnpm/[email protected]/node_modules/tsx/dist/esm/index.mjs?1722219946759:2:2245)
    at async nextLoad (node:internal/modules/esm/hooks:833:22)
    at async Hooks.load (node:internal/modules/esm/hooks:416:20)

version

VSCode: 1.91.1
Node: 20.9.0


My repo, https://github.com/sxzz/eslint-config, uses https://github.com/antfu/eslint-ts-patch powered by tsx and encounters the same error in VSCode.

I can also confirm that this issue also occurs in Vue Language Tools.

Bugs are expected to be fixed by those affected by it

  • I'm interested in working on this issue

Compensating engineering work will speed up resolution and support the project

  • I'm willing to offer $10 for financial support
@privatenumber
Copy link
Owner

I haven't been able to reproduce this.

I cloned your repo, ran nvm i 20.9.0; pnpm lint and it works fine.

I've never used the VSCode ESLint extension but I tried installing it and I'm not even sure how to get it to run or see if it's working/erroring.

I checked out eslint-ts-patch and saw this. Is this relevant?
https://github.com/antfu/eslint-ts-patch#integrations

@sxzz
Copy link
Author

sxzz commented Jul 31, 2024

Forgot to mention 😂
image

eslint-ts-patch refers to VSCode 1.89, but in the latest version 1.91.1, Node has been updated. Therefore, it's not due to an outdated Node version. The same version works fine in CLI.

@privatenumber
Copy link
Owner

Thanks, I was able to reproduce it!

Debugging it, it actually doesn't seem to be a tsx issue. As you can see from the error stack, it's coming from esbuild when it tries to spawn:

TypeError: Cannot read properties of undefined (reading 'size')
    at normalizeSpawnArguments (node:child_process:726:34)
    at Object.spawn (node:child_process:792:13)
    at ensureServiceIsRunning (/github/privatenumber/tsx/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:1993:29)

In esbuild, this is the line:
https://github.com/evanw/esbuild/blob/78f89e41d5e8a7088f4820351c6305cc339f8820/lib/npm/node.ts#L257

It looks like a pretty simple spawn though, so I went into the Node.js v20.9.0 source but I couldn't trace it back:

If VSCode bundles its own version of Node with it, I wonder if it's a modified fork?

@sxzz
Copy link
Author

sxzz commented Jul 31, 2024

I tried running it on VSCodium (a community fork of VSCode). It works well, so I suspect the issue might be with VSCode.

However, if I use esbuild alone, it works on both VSCode, VSCode Insiders, and VSCodium. I guess it might have been broken by some features used by tsx?

import { build } from 'esbuild'

await build({
  stdin: { contents: 'export let a: string', loader: 'ts' },
  write: false,
})

console.log('ok')
image

@sxzz
Copy link
Author

sxzz commented Jul 31, 2024

The bug is confirmed to be caused by VSCode, likely related to the module.register API.

Some part of the code from VSCode isn't open source; I searched the entire GitHub codebase.

@sxzz
Copy link
Author

sxzz commented Jul 31, 2024

Raise an issue upstream: microsoft/vscode#224426

@privatenumber
Copy link
Owner

Wow very nice work @sxzz 🔥 Will wait for it to be resolved upstream.

How did you manage to see into normalizeSpawnArguments?

@sxzz
Copy link
Author

sxzz commented Aug 1, 2024

  • Try debugging a VSCode extension (such as https://github.com/vuejs/language-tools), clone it and press F5.
  • Set a breakpoint in any reachable code, and through the VSCode debug console, get the process.debugPort port number.
image
  • Open chrome://inspect/ in Chrome, click on Open dedicated DevTools for Node.
  • In the new window's connection tab, add localhost:[process.debugPort].
  • You can then see the internal code of node in the sources tab.
image

@privatenumber
Copy link
Owner

Ah amazing! Thanks for the tip @sxzz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants