Hello everyone! New streamlit user here.
I’m testing out v2 components, looking forward to implement my existing React components in streamlit using the new components api.
What I’m facing is an error that tells me: streamlit.errors.StreamlitAPIException: Component ‘custom_components.custom_components’ must be declared in pyproject.toml with asset_dir to use file-backed js.
I’ve followed all the steps in the component-template github, but when I try to run example.py inside my custom component I get the error above.
My folder structure is:
My inner pyproject.toml file is:
[project]
name = “custom_components”
version = “0.0.1”
[[tool.streamlit.component.components]]
name = “custom_components”
asset_dir = “frontend/build”
The outer one is:
[build-system]
requires = [“setuptools>=77.0.3”, “wheel”]
build-backend = “setuptools.build_meta”
[project]
name = “custom_components”
version = “0.0.1”
description = “Streamlit component that allows you to do X”
readme = “README.md”
license = “MIT”
license-files = [“LICENSE”]
requires-python = “>=3.10”
authors = [{ name = “John Smith”, email = “john@example.com” }]
dependencies = [“streamlit >= 1.51”]
[project.optional-dependencies]
devel = [
“wheel”,
“pytest==7.4.0”,
“playwright==1.48.0”,
“requests==2.31.0”,
“pytest-playwright-snapshot==1.0”,
“pytest-rerunfailures==12.0”,
]
[tool.setuptools.packages.find]
include = [“custom_components*”]
[tool.setuptools]
include-package-data = true
[tool.setuptools.package-data]
custom_components = [“frontend/build/**/*”, “pyproject.toml”]
And in my __init_ _.py I’m calling it like this:
out = st.components.v2.component(
"custom_components.custom_components",
js="index-*.js",
html='<div class="react-root"></div>',
)
Any help will be much appretiated!! Thanks
