Yarn error (fatal) on executing JupyterLab

When I run

jupyter lab

I get

Fail to get yarn configuration. Unknown Syntax Error: Extraneous positional argument ("list").

$ yarn config [-v,--verbose] [--why] [--json]

This is new to me (I’ve been using jupyter for years without issues) and seems to have started after I switched to Yarn Modern with

yarn set version berry

I thought perhaps that the issue might be the presence of

nodeLinker: pnp

in my .yarnrc.yml but replacing that with

nodeLinker: node-modules

doesn’t fix anything.

FWIW, .yarnrc.yml also has

yarnPath: .yarn/releases/yarn-3.2.3.cjs

How do I fix this fatal error?

Yep, lab is entirely incompatible with yarn>=2, though i didn’t realize it would fail that hard if not trying to build. There is this existing information: yarn 3.1.1 does not support list command line argument · Issue #12848 · jupyterlab/jupyterlab · GitHub

As upstream keeps putting out 1.x security releases, and not everything supports pnp without hacks, I am not sure of the benefits of changing… and it would only ever be at a major version release and a bit late in the game for 4.x, so you’re looking at this issue for the next year, at least.

Anyhow, as a stopgap, you could try the following untested jupyter_config.json:

{
  "ServerApp": {
    "tornado_settings": {
      "page_config_data": {
        "buildCheck": false,
        "buildAvailable": false
      }
    }
  }

This should hopefully skip all the nodejs-related stuff, and should hopefully never invoke jlpm, etc.

Frankly, I’d love to see all of the nodejs-based stuff dropped from the user-facing jupyterlab package, isolating all of it in a jupyterlab-builder tool a la Drop managing source extensions with `jupyter labextension`? · Issue #11336 · jupyterlab/jupyterlab · GitHub… but that’s neither here nor there.

1 Like

Where’s that config file located?

https://jupyter-server.readthedocs.io/en/latest/other/full-config.html#config-file-and-command-line-options

No mention of jupyter_config.json there. What am I missing?

jupyter_server_config.json and .py are interchangeable, jupyter_config is a fallback. all can be put in the paths it describes finding there with jupyter --paths

Sorry, how do I put the text in your fix into the .py?

You don’t have to (jupyter_server looks for both .py and .json), but it would be like:

# jupyter_server_config.py
c.ServerApp.tornado_settings =  {
      "page_config_data": {
        "buildCheck": false,
        "buildAvailable": false
      }
    }

After adding that (either .py or .json), I still get the same error.

It turns out the way to fix this (duh) is to ensure that Yarn Classic is used, except in repos where it Modern is explicitly wanted and known to work.

The steps to get from this mess to a working JupyterLab configuration are simply:

  1. Reinstall the latest Yarn:

    brew uninstall yarn
    brew install yarn
    brew link --overwrite yarn
    

    This will make Yarn Classic the default globally.

  2. In repos where you want to use Yarn Modern, enable it:

    yarn policies set-version berry
    

    This uses Yarn Modern only in the repo where this command was run, and also ensures that it is used for builds in clones of the repo.

(None of the suggestions for editing jupyter_server.{py|json} have any effect.)