Immich CLI Error

Problem

When attempting to execute the immich CLI, an error occurs, as shown below:

geek@geekpc:/tmp$ immich
file:///usr/local/lib/node_modules/@immich/cli/dist/index.js:1268
    enableOrNameAndArgs = enableOrNameAndArgs ?? "help [command]";
                                               ^

SyntaxError: Unexpected token '?'
    at Loader.moduleStrategy (internal/modules/esm/translators.js:133:18)
    at async link (internal/modules/esm/module_job.js:42:21)

Cause

The error stems from a syntax issue within the Node.js environment.

Solution

Update Node.js: Ensure that you have the latest version of Node.js installed. Use a version manager like NVM (Node Version Manager) for easy management of Node.js versions.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm ls-remote
nvm install v22.1.0

After updating Node.js, reattempt executing the immich CLI. You should now be able to use the CLI without encountering the syntax error.

geek@geekpc:~$ immich
Usage: immich [options] [command]

Command line interface for Immich

Options:
  -V, --version                       output the version number
  -d, --config-directory <directory>  Configuration directory where auth.yml will be stored (default:
                                      "/home/geek/.config/immich/", env: IMMICH_CONFIG_DIR)
  -u, --url [url]                     Immich server URL (env: IMMICH_INSTANCE_URL)
  -k, --key [key]                     Immich API key (env: IMMICH_API_KEY)
  -h, --help                          display help for command

Commands:
  login|login-key <url> <key>         Login using an API key
  logout                              Remove stored credentials
  server-info                         Display server information
  upload [options] [paths...]         Upload assets
  help [command]                      display help for command