Why does Typst not find packages in ./local/share/typst?

Dear all,

I installed typst on ubuntu (22) by downloading the typst binary and copying it to /usr/bin. So far so good :). I then wanted to use the basic-report template, but customize it beforehand. So I placed it in:

~/.local/share/typst/packages/local/basic-report/0.3.1/.

Note, that I had to create the typst directory and its subdirectories here myself, they were not created by typst.

I import the template into my main.typ file by:

#import "@local/basic-report:0.3.1": *

However, compiling the file yields:

#import error: package not found (searched for @local/basic-report:0.3.1)

It does work if I place the template folder in:

~/.cache/typst/packages/local/basic-report/0.3.1

I know that the snap install of typst has similar problems right now, and at first I had it installed via snap but removed it and downloaded the binary from the github releases page. I also tried to reboot several times.
Did someone encounter the same problem and has some pointers for me ?

Thank you very much!

Cheers
Tim

Hi! It works perfectly on my Ubuntu.
I installed typst via GitHub from the begininng and didn’t use snap. However, I don’t think it will make any difference.

Could you share more information? Does which -a typst verify your installation? Have you set $XDG_DATA_HOME? What will happen if you specify the dir explicity (typst compile --package-path … …)?

Typst will create the file ~/.local/share/typst/greeted when you run typst without any argument for the first time. This feature might help you figure out what’s happening.

3 Likes

Hi!
Thank you for the quick response.
I set XDG_DATA_HOME to ~/.local/share and now it works.
Explicitly setting the package path worked as well, good to know that option. Thank you so much!

1 Like

Fine!

Actually, I didn’t set $XDG_DATA_HOME. But let’s investigates the detail when another person encounters it.

1 Like

I got the exact same problem.
Solved by: $ export XDG_DATA_HOME=$HOME/.local/share

typst 0.13.1 (8ace67d9) Downloaded from github
Description: Ubuntu 24.04.3 LTS

1 Like

Typst v0.13.1 yields the same package not found error for several cases. Therefore, it’s hard to debug without editing the source code and recompiling typst.

Improving error messages in case of package not found by Vanille-N · Pull Request #6433 · typst/typst · GitHub is working on improve the message. Hope we can solve the mystery in v0.14.

EDIT: I believe it’s a typst bug, although I can’t prove it. Besides, I find that ~/.local/share/typst/greeted won’t be created if ~/.local/share/typst does not exist.

I just tried with a clean Ubuntu (container docker.io/library/ubuntu:22.04) and it works without having to set XDG_DATA_HOME so I wonder what the problem was. @Tim_Maier , @Raul_Durand could you try to remove your configuration that sets XDG_DATA_HOME, reboot and run “echo $XDG_DATA_HOME” to check if it was set to something else?

How can you be sure that a container version is the same as the full-fledged distro? Almost no container version is the same as the real deal, as everyone tries to save up on container image size. If you used snap version, it would be weird that it did work. Maybe snap also have different behavior in containers…

It’s only around 74 MiB.

I’m sure it’s not the same. My guess is that the full distro or something on top of it defines XDG_DATA_HOME, hence my question.

If I remove the export line in .bashrc, reboot and echo the XDG_DATA_HOME the terminal prints an empty line.

1 Like

I got the same result here.

If you are willing to debug, could you execute the following commands and see if we get the same output?

Commands without output (for copying)
mv ~/.local/share/typst somewhere/to/backup/typst

typst --version
echo $XDG_DATA_HOME
ls ~/.local/share/typst

echo '#import "@local/foo:0.0.2": *' | typst compile - - --format svg

mkdir -p ~/.local/share/typst/packages/local/foo/0.0.1/
echo '#import "@local/foo:0.0.1": *' | typst compile - - --format svg

touch ~/.local/share/typst/packages/local/foo/0.0.1/typst.toml
echo '#import "@local/foo:0.0.1": *' | typst compile - - --format svg
  1. Backup and move your ~/.local/share/typst elsewhere.

  2. Check env info:

    âžś  ~ typst --version
    typst 0.13.1 (8ace67d9)
    âžś  ~ echo $XDG_DATA_HOME
    
    âžś  ~ ls ~/.local/share/typst
    ls: cannot access '/home/USER/.local/share/typst': No such file or directory
    
  3. Compile a non-existent local package.

    âžś  ~ echo '#import "@local/foo:0.0.2": *' | typst compile - - --format svg
    error: package not found (searched for @local/foo:0.0.2)
      ┌─ <stdin>:1:8
      │
    1 │ #import "@local/foo:0.0.2": *
      │         ^^^^^^^^^^^^^^^^^^
    
  4. Create an empty directory for the local package, and recompile.

    âžś  ~ mkdir -p ~/.local/share/typst/packages/local/foo/0.0.1/
    âžś  ~ echo '#import "@local/foo:0.0.1": *' | typst compile - - --format svg
    error: file not found (searched at /home/USER/.local/share/typst/packages/local/foo/0.0.1/typst.toml)
      ┌─ <stdin>:1:8
      │
    1 │ #import "@local/foo:0.0.1": *
      │         ^^^^^^^^^^^^^^^^^^
    

    The error message changes from package not found to file not found, which means that typst is searching at the right place.

  5. Create an empty typst.toml in that directory, and recompile.

    âžś  ~ touch ~/.local/share/typst/packages/local/foo/0.0.1/typst.toml
    âžś  ~ echo '#import "@local/foo:0.0.1": *' | typst compile - - --format svg
    error: package manifest is malformed (missing field `package`)
      ┌─ <stdin>:1:8
      │
    1 │ #import "@local/foo:0.0.1": *
      │         ^^^^^^^^^^^^^^^^^^
    

    The error message becomes package manifest is malformed, further confirming the situation.

If you are still interested, you can run typst info with the new version to see the exact environment.

âžś  ./typst info
Version 0.14.0-rc.1 (6b79d120, linux on x86_64)

Build settings
…

Packages
  Package path       /home/USER/.local/share/typst/packages
  Package cache path /home/USER/.cache/typst/packages

…
1 Like

Hey folks,

If it helps anything: I just had the XDG_DATA_HOME="$HOME/.local/share" line in bashrc commented out by accident and suddenly that variable held the path /home/USERNAME/snap/code/211/.local/share .

1 Like