psalm: Uncaught Error: Class "DOMDocument" not found

Summary

I use the VSCode extension for running Psalm inside the editor. When opening a PHP Symfony project, Psalm crashes immediately multiple times and shuts down.

The error is as follows:

[INFO] Starting language server
[INFO] Psalm Version was detected as 4.19.0
[ERROR] Uncaught Error: Class "DOMDocument" not found in /path/to/project/vendor/vimeo/psalm/src/Psalm/Config.php:707
Stack trace:
#0 /path/to/project/vendor/vimeo/psalm/src/Psalm/Config.php(734): Psalm\Config::loadDomDocument()
#1 /path/to/project/vendor/vimeo/psalm/src/Psalm/Config.php(697): Psalm\Config::validateXmlConfig()
#2 /path/to/project/vendor/vimeo/psalm/src/Psalm/Config.php(661): Psalm\Config::loadFromXML()
#3 /path/to/project/vendor/vimeo/psalm/src/Psalm/Internal/CliUtils.php(491): Psalm\Config::loadFromXMLFile()
#4 /path/to/project/vendor/vimeo/psalm/src/Psalm/Internal/Cli/LanguageServer.php(255): Psalm\Internal\CliUtils::initializeConfig()
#5 /path/to/project/vendor/vimeo/psalm/psalm-language-server(7): Psalm\Internal\Cli\LanguageServer::run()
#6 {main}
(Psalm 4.19.0@a2ad69ae4f5ab1f7d225a8dc4e2ec2d9415ed599 crashed due to an uncaught Throwable)

When running Psalm via CLI, $ vendor/bin/psalm, everything works normal.

Which additional information do you need?

System Info

  • PHP version: PHP 8.1.2 (cli) (built: Jan 24 2022 10:43:09) (NTS) Copyright © The PHP Group Zend Engine v4.1.2, Copyright © Zend Technologies with Zend OPcache v8.1.2, Copyright ©, by Zend Technologies
  • Psalm version: 4.19.0

User Settings

phpExecutablePath: "/usr/bin/php"
phpExecutableArgs: ["-dxdebug.remote_autostart=0","-dxdebug.remote_enable=0","-dxdebug_profiler_enable=0"]
psalmVersion: null
psalmScriptPath: "vendor/vimeo/psalm/psalm-language-server"
psalmScriptArgs: []
disableAutoComplete: false
maxRestartCount: 5
unusedVariableDetection: false
enableVerbose: false
connectToServerWithTcp: false
enableUseIniDefaults: false
logLevel: "INFO"
analyzedFileExtensions: [{"scheme":"file","language":"php"},{"scheme":"untitled","language":"php"}]
configPaths: ["psalm.xml","psalm.xml.dist"]
hideStatusMessageWhenRunning: true

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Yeah, my bad. I had this issue time ago and just remembered how I fixed it.

Had to run $ sudo apt-get install php8.1-xml indeed.

But I actually just have this one version of PHP installed, yes.

Also, maybe the php-dom extension is not correct anymore?

It’s correct. The dom extension requires the xml extension, I would guess Debian or Ubuntu decided to package them together since they’re closely related, but they’re still separate extensions to PHP.

Okay, I re-checked the issue just now.

When the XML extension is not loaded, BOTH the language server and the CLI don’t work. Which makes sense, right?

Not sure how I missed it, but I ran the language server locally and the CLI in my docker container (where the extension is installed already). I did not notice at first, because I consider them different environments.

However, I created a fresh PHP project, installed Psalm and it did not tell me about to require the extension. So I think having a nicer error message shown would be great!

CC @AndrolGenhald

@orklah we should actually define this as a requirement in composer.json of psalm