Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: building Next.js + SSR components - 'ReferenceError: Node is not defined' #537

Open
3 tasks done
guilhermebc opened this issue Nov 4, 2024 · 2 comments
Open
3 tasks done
Labels

Comments

@guilhermebc
Copy link

Prerequisites

Stencil Version

4.21.0

Stencil Framework Output Target

React

Stencil Framework Output Target Version

0.7.1

Current Behavior

I work at a company where we use Stencil for the internal design system and export it to React, as we have projects in Next.js (^14.2.3).

We use version ^0.5.3 of the @stencil/react-output-target package for using the components in Next.js projects and were waiting for the launch of SSR support.

As soon as the SSR components support was released for react-output-target, I went to test updating it in the company's design system, but I am not able to compile the application, I followed all the steps in the Stencil documentation.

Our design system is published in a private repository manager, and we install it in the company's applications (Vue apps, Next.js apps, etc).

➜  nextjs-with-stencil-ssr git:(main) ✗ 
yarn build
yarn build
yarn run v1.22.22
$ next build
  ▲ Next.js 14.2.11

   Creating an optimized production build ...
 ✓ Compiled successfully
 ✓ Linting and checking validity of types    
 ✓ Collecting page data    
   Generating static pages (0/5)  [=   ]ReferenceError: Node is not defined
    at ta (/Users/guilherme.costa/workspace/nextjs-with-stencil-ssr/.next/server/app/page.js:1:85335)
    at e6 (/Users/guilherme.costa/workspace/nextjs-with-stencil-ssr/.next/server/app/page.js:1:83143)
    at td (/Users/guilherme.costa/workspace/nextjs-with-stencil-ssr/.next/server/app/page.js:1:86752)
    at 4978 (/Users/guilherme.costa/workspace/nextjs-with-stencil-ssr/.next/server/app/page.js:1:91142)
    at Object.t [as require] (/Users/guilherme.costa/workspace/nextjs-with-stencil-ssr/.next/server/webpack-runtime.js:1:128)
    at require (/Users/guilherme.costa/workspace/nextjs-with-stencil-ssr/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:16:18224)
    at I (/Users/guilherme.costa/workspace/nextjs-with-stencil-ssr/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:94362)
    at C (/Users/guilherme.costa/workspace/nextjs-with-stencil-ssr/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:92913)
    at rP (/Users/guilherme.costa/workspace/nextjs-with-stencil-ssr/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:33974)
    at nN (/Users/guilherme.costa/workspace/nextjs-with-stencil-ssr/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:62304) {
  digest: '1355879404'
}

Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error

ReferenceError: Node is not defined
    at ta (/Users/guilherme.costa/workspace/nextjs-with-stencil-ssr/.next/server/app/page.js:1:85335)
    at e6 (/Users/guilherme.costa/workspace/nextjs-with-stencil-ssr/.next/server/app/page.js:1:83143)
    at td (/Users/guilherme.costa/workspace/nextjs-with-stencil-ssr/.next/server/app/page.js:1:86752)
    at 4978 (/Users/guilherme.costa/workspace/nextjs-with-stencil-ssr/.next/server/app/page.js:1:91142)
    at Object.t [as require] (/Users/guilherme.costa/workspace/nextjs-with-stencil-ssr/.next/server/webpack-runtime.js:1:128)
    at require (/Users/guilherme.costa/workspace/nextjs-with-stencil-ssr/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:16:18224)
    at I (/Users/guilherme.costa/workspace/nextjs-with-stencil-ssr/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:94362)
    at C (/Users/guilherme.costa/workspace/nextjs-with-stencil-ssr/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:92913)
    at rP (/Users/guilherme.costa/workspace/nextjs-with-stencil-ssr/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:33974)
    at nN (/Users/guilherme.costa/workspace/nextjs-with-stencil-ssr/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:62304)
 ✓ Generating static pages (5/5)

> Export encountered errors on following paths:
        /page: /
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Expected Behavior

Setup Next.js app router + SSR + Stencil react output target components.server building and working

Steps to Reproduce

Design system repo: https://github.com/guilhermebc/gbc-design-system
Nextjs app + design system repo: https://github.com/guilhermebc/nextjs-with-stencil-ssr

The version @guilhermebc/[email protected] is causing the error.

I ended up discovering that the cause of the error is coming from the extra settings we need to apply for slot correction:
stencil.config.ts

extras: {
    enableImportInjection: true,
    experimentalSlotFixes: true,
    scopedSlotTextContentFix: true,
}

I generated a version @guilhermebc/[email protected] removing these extra settings and the error does not occur, but in any case, we need these settings applied in our internal design system.

To reproduce, just download the repository https://github.com/guilhermebc/nextjs-with-stencil-ssr:
1 - Install the dependencies yarn install
2 - Run build with yarn build

PS: To simulate without the error, just install the version @guilhermebc/[email protected]

Code Reproduction URL

https://github.com/guilhermebc/nextjs-with-stencil-ssr

Additional Information

Screenshot 2024-11-04 at 11 56 55

@ionitron-bot ionitron-bot bot added the triage label Nov 4, 2024
Copy link

ionitron-bot bot commented Nov 4, 2024

Thanks for the issue!

This project is currently maintained for the purposes of supporting Ionic Framework. At this time, only new issues & pull requests that support Ionic Framework will be prioritized. For the latest updates regarding the maintenance status of this project, please see this section of the project's README

@guilhermebc
Copy link
Author

up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant