ionic-team / stencil

A toolchain for building scalable, enterprise-ready component systems on top of TypeScript and Web Component standards. Stencil components can be distributed natively to React, Angular, Vue, and traditional web developers from a single, framework-agnostic codebase.
https://stenciljs.com
Other
12.51k stars 783 forks source link

bug: TypeError: Cannot read properties of undefined (reading 'createHTMLDocument') when using renderToString in NextJS #5978

Open vivere-dally opened 2 weeks ago

vivere-dally commented 2 weeks ago

Prerequisites

Stencil Version

4.21.0

Current Behavior

Followed the hydrate docs and added a new output target:

  {
    type: 'dist-hydrate-script',
  },

Running build produces and output.

import { renderToString } from 'mypkg';

export default async function handler(req, res) {
  const resp = await renderToString('<mycomponent></mycomponent>', {
    fullDocument: false,
  });
  res.status(200).send(resp);
}

causes

error - TypeError: Cannot read properties of undefined (reading 'createHTMLDocument') at .../node_modules/mypkg/index.js:12292:37 at .../node_modules/mypkg/index.js:12295:4 at .../node_modules/mypkg/index.js:2226:4 at .../node_modules/mypkg/index.js:2236:4 at hydrateAppClosure (.../node_modules/mypkg/index.js:12857:2) at hydrateFactory (.../node_modules/mypkg/index.js:23821:3) at .../node_modules/mypkg/index.js:39166:37

Expected Behavior

work

System Info

System: node 20.12.2
    Platform: darwin (23.6.0)
   CPU Model: Apple M3 Pro (12 cpus)
    Compiler: .../node_modules/@stencil/core/compiler/stencil.js
       Build: 1724698030
     Stencil: 4.21.0 🐷
  TypeScript: 5.5.3
      Rollup: 2.56.3
      Parse5: 7.1.2
      jQuery: 4.0.0-pre
      Terser: 5.31.1

Steps to Reproduce

Just add the hydrate output to an existing working stencil components project

Code Reproduction URL

no

Additional Information

No response

tanner-reits commented 1 week ago

@vivere-dally I checked things out in a prerender app I have and didn't experience any errors. If you have a reproduction case that's failing I can take a look at that, but won't be able to offer help otherwise.