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

Svelte VS Code extension keeps crashing (TypeError: Cannot read properties of undefined (reading 'sourceFile')) #2228

Closed
marianmeres opened this issue Dec 10, 2023 · 6 comments
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.

Comments

@marianmeres
Copy link

marianmeres commented Dec 10, 2023

Describe the bug

VSCode Svelte Extension keeps crashing on a npm workspaces based Sveltekit typescript project. On other non workspaces Svelte/kit projects it seems to be running fine.

I'm seeing this (or very similar) error output:

Node.js v18.15.0
[Info  - 12:16:16] Connection to server got closed. Server will restart.
true
Initialize language server at  file:///<...omitted...>
Initialize new ts service at  <...omitted...>/tsconfig.json
Trying to load configs for <...omitted...>
Loaded config at  <...omitted...>/svelte.config.js
SnapshotManager File Statistics:
Project files: 22
Svelte files: 9
From node_modules: 0
Total: 22
Reloading ts service at  <...omitted...>/tsconfig.json  due to config updated
Trying to load configs for <...omitted...>
SnapshotManager File Statistics:
Project files: 22
Svelte files: 9
From node_modules: 1
Total: 23
/Users/mm/.vscode/extensions/svelte.svelte-vscode-108.1.0/node_modules/typescript/lib/typescript.js:134135
    return !!entry.sourceFile;
                   ^

TypeError: Cannot read properties of undefined (reading 'sourceFile')
    at isDocumentRegistryEntry (/Users/mm/.vscode/extensions/svelte.svelte-vscode-108.1.0/node_modules/typescript/lib/typescript.js:134135:20)
    at getDocumentRegistryEntry (/Users/mm/.vscode/extensions/svelte.svelte-vscode-108.1.0/node_modules/typescript/lib/typescript.js:134211:21)
    at Object.releaseDocumentWithKey (/Users/mm/.vscode/extensions/svelte.svelte-vscode-108.1.0/node_modules/typescript/lib/typescript.js:134306:21)
    at /Users/mm/.vscode/extensions/svelte.svelte-vscode-108.1.0/node_modules/typescript/lib/typescript.js:142983:67
    at forEach (/Users/mm/.vscode/extensions/svelte.svelte-vscode-108.1.0/node_modules/typescript/lib/typescript.js:55:24)
    at cleanupSemanticCache (/Users/mm/.vscode/extensions/svelte.svelte-vscode-108.1.0/node_modules/typescript/lib/typescript.js:142983:9)
    at Object.dispose (/Users/mm/.vscode/extensions/svelte.svelte-vscode-108.1.0/node_modules/typescript/lib/typescript.js:142988:7)
    at Object.dispose (/Users/mm/.vscode/extensions/svelte.svelte-vscode-108.1.0/node_modules/svelte-language-server/dist/src/plugins/typescript/service.js:428:25)
    at /Users/mm/.vscode/extensions/svelte.svelte-vscode-108.1.0/node_modules/svelte-language-server/dist/src/plugins/typescript/service.js:546:33
    at async Promise.all (index 0)

Node.js v18.15.0
[Error - 12:17:05] The Svelte server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.

Reproduction

Create a npm workspace project with 2 workspaces where one is a Sveltekit typescript "library" project (a) and the other is a regular Svelte typescript (non sveltekit) project (b) where "b" is dependant on "a" (the non-kit "b" imports the lib from "a").

Expected behaviour

No crashing.

System Info

VSCode report:

Version: 1.85.0
Commit: af28b32d7e553898b2a91af498b1fb666fdebe0c
Date: 2023-12-06T18:17:50.719Z
Electron: 25.9.7
ElectronBuildId: 25551756
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Darwin arm64 23.1.0

Which package is the issue about?

Svelte for VS Code extension

Additional Information, eg. Screenshots

No response

@marianmeres marianmeres added the bug Something isn't working label Dec 10, 2023
@marianmeres marianmeres changed the title VSCode extension keeps crashing (TypeError: Cannot read properties of undefined (reading 'sourceFile')) Svelte VS Code extension keeps crashing (TypeError: Cannot read properties of undefined (reading 'sourceFile')) Dec 10, 2023
@jasonlyu123
Copy link
Member

jasonlyu123 commented Dec 11, 2023

This actually happens to any projects with "moduleResolution": "NodeNext" when the jsconfig.json or ./.svelte-kit/tsconfig.json is saved.

Another problem is why your tsconfig gets updated as soon as your language server is started. I only get it to crash every time I save the tsconfig/jsconfig. Wondering if that will cause any performance problems. Do you keep restarting the dev server? If not, Can you provide a reproduction repository so we can check why the tsconfig consistently got updated? I think it might also not be related to the npm workspace, So can you try to provide a repo without it?

@marianmeres
Copy link
Author

marianmeres commented Dec 11, 2023

Thanks @jasonlyu123 for quick response.

If I understand correctly what you're asking: once I see that crash error message toast in vs code I always restart the Svelte language server (but not the vite dev server), and I also obviously regularly restart the dev server as well, although not after each crash... But I almost never edit tsconfig.json, I'm using the default from project scaffolding.

My suspicion to npm workspaces was because I have tens of Svelte projects on my machine, but only the one with workspace is crashing.

I'll try to prepare the reproduction repo soon. Thanks.

(And yes, I'm using the NodeNext module resolution in that project.)

@jasonlyu123
Copy link
Member

If you did actually restart the Vite server five times in 3 minutes, then we don't need a reproduction. SvelteKit will override the tsconfig file when the dev server starts. I just wanted to make sure if it's something that will overwrite the file repeatedly. Also, I found that the problem that caused the crash was tracked in #1965, which is a hard problem to solve. So if you did manually restart that many times, I am going to close this, and let's track the issue in #1965.

@marianmeres
Copy link
Author

marianmeres commented Dec 11, 2023

OK, I see what you mean - no, I didn't restart the dev server that much. When I said "regularly", that is, maybe, once in an hour (depends on many things)...

@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Dec 13, 2023
@sharsat
Copy link

sharsat commented Jan 7, 2024

I had a similar problem with svelte when I tried to open an external one and not one created by me. I fixed it by replacing the folder called "nodes_module" with one that was created by my macbook. Maybe that can work out for you as well :)

@ieedan
Copy link

ieedan commented Jan 9, 2024

Having this same issue with it crashing. It does seem to come up more often if I am copy pasting large amounts of code at once. Also doesn't seem to like when I try to import things.

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

No branches or pull requests

5 participants