Skip to content

Vitest extension crashes if it encounters a package.json that isn't valid JSON #719

@TomerAberbach

Description

@TomerAberbach

Describe the bug

The extension crashes if it encounters a package.json that isn't valid JSON.

I encountered this in my project because I have a templated package.json file (I replace the templated pieces later) and the template itself is not valid JSON.

Reproduction

Add a package.json file to the project that doesn't contain valid JSON.

https://github.com/TomerAberbach/vitest-extension-bug

Output

[INFO 4:23:52 PM] [v0.0.0] Vitest extension is activated because Vitest is installed or there is a Vite/Vitest config file in the workspace.
[Error 4:23:52 PM] [Error SyntaxError] /Users/tomeraberbach/Desktop/vitest-bug/dir/package.json: Unexpected token 'i', "invalid
" is not valid JSON
SyntaxError: /Users/tomeraberbach/Desktop/vitest-bug/dir/package.json: Unexpected token 'i', "invalid
" is not valid JSON
	at parse (<anonymous>)
	at Module._extensions..json (node:internal/modules/cjs/loader:1860:39)
	at Module.load (node:internal/modules/cjs/loader:1448:32)
	at Module._load (node:internal/modules/cjs/loader:1270:12)
	at c._load (node:electron/js2c/node_init:2:17993)
	at e._load (file:///Applications/Visual%20Studio%20Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:405:6054)
	at t._load (file:///Applications/Visual%20Studio%20Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:223:22716)
	at r._load (file:///Applications/Visual%20Studio%20Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:215:24094)
	at TracingChannel.traceSync (node:diagnostics_channel:328:14)
	at wrapModuleLoad (node:internal/modules/cjs/loader:244:24)
	at Module.require (node:internal/modules/cjs/loader:1470:12)
	at require (node:internal/modules/helpers:147:16)
	at /Users/tomeraberbach/.vscode/extensions/vitest.explorer-1.38.1/dist/extension.js:13:18167
	at Array.forEach (<anonymous>)
	at yv (/Users/tomeraberbach/.vscode/extensions/vitest.explorer-1.38.1/dist/extension.js:13:18134)
	at async Xl (/Users/tomeraberbach/.vscode/extensions/vitest.explorer-1.38.1/dist/extension.js:13:17448)
	at async Wo._defineTestProfiles (/Users/tomeraberbach/.vscode/extensions/vitest.explorer-1.38.1/dist/extension.js:32:2170)
	at async Wo.defineTestProfiles (/Users/tomeraberbach/.vscode/extensions/vitest.explorer-1.38.1/dist/extension.js:32:1997)
	at async Wo.activate (/Users/tomeraberbach/.vscode/extensions/vitest.explorer-1.38.1/dist/extension.js:32:8563)
	at async tT (/Users/tomeraberbach/.vscode/extensions/vitest.explorer-1.38.1/dist/extension.js:32:660)
	at async aA.n (file:///Applications/Visual%20Studio%20Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:116:13398)
	at async aA.m (file:///Applications/Visual%20Studio%20Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:116:13361)
	at async aA.l (file:///Applications/Visual%20Studio%20Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:116:12817)

Extension Version

1.38.1

Vitest Version

4.0.18

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions