How to replace JupyterLab extension with your own?

I’m trying to replace the implementation of the command ‘notebook:export-to-format’ so I disabled JupyterLab’s notebook-extension, copied this extension, modified the exportToFormat implementation, and I install the notebook-extension back as an extension, like this:

# 1. get and install JupyterLab
RUN wget https://github.com/jupyterlab/jupyterlab/archive/v1.0.0a5.tar.gz -O jupyterlab.tar.gz \
  && tar -xvzf jupyterlab.tar.gz
WORKDIR jupyterlab-1.0.0a5
RUN cd jupyterlab-1.0.0a5 \
  && pip install -e . \
  && jlpm install

# 2. disable default notebook-extension
RUN jupyter labextension disable notebook-extension

# 3. install notebook-extension from local dir
RUN cd /opt/my_jupyterlab_extensions/notebook-extension \
  && npm install  \
  && npm run build \
  && jupyter labextension install

It build ok but when the application starts, I get errors from all the extensions that require INotebookTracker:

jupyter labextension list shows the notebook-extension installed OK.

Am I doing something wrong?

The additional things I did to make it work was:

  • from tsconfig.json I removed references (due to relative paths)
  • in package.json I left the extension name, extension version, plugin ids, as defined in the original core’s notebook-extension.

I checked that the modified notebook-extension version is the same that all the other core’s extensions require (“1.0.0-alpha.8”).

Having said that, maybe there is an easier way to replace the implementation of a command ‘notebook:export-to-format’ (than by disabling, customizing, and installing a whole extension)?

Hello!

My suspicion is that your package.json has dependencies whose versions mismatch with the version in JupyterLab. In particular, the INotebookTracker that you are importing from @jupyterlab/notebook must match the one everyone else is importing, otherwise, the other packages won’t accept your token as the correct one.

1 Like

Thanks afshin! I’ll check the versions of dependencies are synced.