mdx-analyzer icon indicating copy to clipboard operation
mdx-analyzer copied to clipboard

Crash in VS Code

Open JonnyBurger opened this issue 1 year ago • 2 comments

Initial checklist

Affected packages and versions

1.8.11

Link to runnable example

No response

Steps to reproduce

Open a MDX in VS Code

Expected behavior

No Crash

Actual behavior

[Info  - 10:27:07] Connection to server got closed. Server will restart.
true
/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:41833
  const rootExpression = (_a = sourceFile.statements[0]) == null ? void 0 : _a.expression;
                                                    ^

TypeError: Cannot read properties of undefined (reading '0')
    at convertConfigFileToObject (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:41833:53)
    at parseOwnConfigOfJsonSourceFile (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:42667:16)
    at parseConfig (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:42566:97)
    at parseJsonConfigFileContentWorker (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:42294:24)
    at Object.parseJsonSourceFileConfigFileContent (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:42263:18)
    at a (/Users/jonathanburger/.vscode/extensions/unifiedjs.vscode-mdx-1.8.11/out/language-server.js:897:19013)
    at /Users/jonathanburger/.vscode/extensions/unifiedjs.vscode-mdx-1.8.11/out/language-server.js:897:18633
    at $fe (/Users/jonathanburger/.vscode/extensions/unifiedjs.vscode-mdx-1.8.11/out/language-server.js:85:5357)
    at d (/Users/jonathanburger/.vscode/extensions/unifiedjs.vscode-mdx-1.8.11/out/language-server.js:85:12248)
    at S (/Users/jonathanburger/.vscode/extensions/unifiedjs.vscode-mdx-1.8.11/out/language-server.js:85:12018)

Affected runtime and version

code --version: 1.94.0 d78a74bcdfad14d5d3b1b782f87255d802b57511 arm64

Affected package manager and version

No response

Affected OS and version

No response

Build and bundle tools

Docusaurus

JonnyBurger avatar Oct 12 '24 08:10 JonnyBurger

Please provide a repo to reproduce the issue.

remcohaszing avatar Oct 17 '24 17:10 remcohaszing

Hi! Thanks for taking the time to contribute! This has been marked by a maintainer as needing a reproduction: It’s not yet clear whether this is a problem. Here are a couple tips:

  • Thoroughly document how to reproduce the problem, in steps or with code
  • Don’t link to your complete project: make the repro as tiny as possible, preferrably with only the problematic project in question
  • Make sure you’re on the latest versions of projects (and node/npm/yarn!)
  • The best issue report is a failing test proving it

Thanks, — bb

github-actions[bot] avatar Oct 17 '24 17:10 github-actions[bot]

I’m closing this, because there is no reproduction.

remcohaszing avatar May 31 '25 18:05 remcohaszing

Hi! This was closed. Team: If this was fixed, please add phase/solved. Otherwise, please add one of the no/* labels.

github-actions[bot] avatar May 31 '25 18:05 github-actions[bot]

@JonnyBurger I've raised #513 to fix this, but if you don't want to wait for that you can patch your local extension code by inserting the following line where I show in the screenshot.

d=n.findConfigFile(d, n.sys.fileExists);
Image

bradleyayers avatar Jul 30 '25 00:07 bradleyayers

@remcohaszing I sometimes have the same error and then it shows a popup by VSCode: The MDX server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information

Then the output shows what @JonnyBurger has in his first post.

It happened on opening up the .mdx file. The contents of my .mdx file is some standard Storybook stuff; A couple of imports from @storybook, an import * as Stories from './file.stories``, some headers (#`) and two TypeScript code blocks. Nothing crazy.

The formatting of the mdx file still seems to be active. Not sure how the stopped MDX server affects me. I don't seem to miss it?

TomONeill avatar Aug 18 '25 11:08 TomONeill

I can’t confirm or troubleshoot bugs without a reproduction. It looks like the bug is confirmed upstream in https://github.com/volarjs/volar.js/issues/283. That’s also where the fix is.

remcohaszing avatar Aug 18 '25 11:08 remcohaszing

@TomONeill if you're using TypeScript, and project references (in tsconfig.json files), make sure all the project references are paths to tsconfig.json (rather than directories). This works around the issue.

bradleyayers avatar Aug 18 '25 11:08 bradleyayers

Thanks @bradleyayers but I am not. I am using NX though which does have paths defined in a base tsconfig, which points to an index.ts file. Tried it regardless, but nope. Guess I will have to wait for the official patch. Hopefully soon. If the bug and fix are in the upstream, it should be doable today, no?

TomONeill avatar Aug 18 '25 18:08 TomONeill

Are you able to share the tsconfig and directory/file structure? In my case this error came from it not being able to find the tsconfig.json for a given file, so both the tsconfig and the file structure is quite important. Or even better if you can link to the repo if it's public.

bradleyayers avatar Aug 19 '25 02:08 bradleyayers

Here's a reproduction (it's not minimal, but it should be sufficient).

git clone https://github.com/epicweb-dev/mcp-fundamentals.git

Then open up any of the *.mdx files in that repository in an editor with the extension and you'll reproduce this issue.

Image
/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:42623
  const rootExpression = (_a = sourceFile.statements[0]) == null ? void 0 : _a.expression;
                                                    ^

TypeError: Cannot read properties of undefined (reading '0')

I'm guessing either #513 or #512 could resolve this and I would love that :)

kentcdodds avatar Sep 23 '25 16:09 kentcdodds

It's happening quite often while using Cursor

j-machado avatar Oct 07 '25 08:10 j-machado