Closed janforland closed 5 months ago
@janforland thanks for raising the issue!
We have been working on support for Declarative Shadow DOM in Stencil in #5792 and will provide support for using Stencil in Next.js applications as a next step.
closing in favor of #5831
Prerequisites
Stencil Version
2.19.2
Current Behavior
We have created a React component library using Stencil. This library is called FormDS. But, we are experiencing some issues using this library in a Next.js application. This issue seems to be related to the SSR of Next:
Our
stencil.config.ts
file looks like this:This issue seems to be related to the loader file that the
dist
output target produces. This is an auto-generated file from Stencil. The first lines of this file looks like this:And the directory
@formds/core/loader
contains these files:If we directly edit the
index.js
file in the@formds/core-react
folder innode_modules
from what it is auto-generated as, to this:import { defineCustomElements } from '@formds/core/loader/index.cjs.js
Then everything works just fine.
Also, this problem only occurs on the server, not in client. Meaning, if I load a page in Next, and edit the page code to implement a component from my Stencil React components; then, when the HMR has run, everything will seemingly look just fine. It's only when you manually refresh the browser, and therefore force the server to run, that the error occurs.
Expected Behavior
We would expect the produced React components to just work in Next.js, without having to manully edit the loader file extension in the import statement from the react package.
Steps to Reproduce
create-next-app
commandnpm run dev
Code Reproduction URL
https://github.com/janforland/stencil-next-bug/blob/main/package.json
Additional Information
Sadly, the
@formds
packages are hosted on a private repo, so you will not be able to run the Github project :(