Hi, I’ve been struggling to use a local svg file in my JupyterLab extension. I end up getting an error:
ModuleNotFoundError: Module not found: Error: Can't resolve './my_image.svg' in '/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/share/jupyter/lab/staging/node_modules/my_extension/lib'
My relevant code:
import * as logo from './my_image.svg'
class mywidget extends Widget {
constructor() {
super()
this.img = document.createElement('img');
this.node.appendChild(this.img);
this.img.src = logo.toString();
}
readonly img: HTMLImageElement;
}
I have a custom.d.ts
that I placed in the same directory.
declare module "*.svg" {
const content: any;
export default content;
}
My IDE recognizes the svg file fine, and if I change it to an external url it also works fine. But when I run npm run build
and then rebuild the the extension jupyter labextension link .
(or just letting it rebuild in watch mode), it throws the error.
Another way to put my question is how would I use a local image file in the APOD tutorial, instead of from an external url?
UPDATE
I can load local SVG files by switching over to webpack and using the svg-url-loader like in the theme cookiecutter (https://github.com/jupyterlab/theme-cookiecutter/blob/master/{{cookiecutter.extension_name}}/webpack.config.js), but is there a way to do this without using webpack?