Question T5403
Visible to All Users

NextJS with SurveyJS

created 4 years ago

Hello There,
We are planning to integrate SurveyJS with one of our NextJS based application. But we are facing an issue with SSR, since the window object is not available in node server environment. We are planning to build the developer license, but need to have a proper solution for this issue. We tried to load the library dynamically but since surveyjs creator using wild card import that is also not working. I am sorry if this question is a dump :(

Thanks

Answers approved by surveyjs Support

created 4 years ago

Hello Shine,
Theoretically, Survey Model should work in NodeJS. However, we have this file and some code in the base.ts that uses window and document.
Do you have issues in run-time? I believe we are talking about SurveyJS Library only, aren't we?

Thank you,
Andrew
SurveyJS Team

    Other Answers

    created 2 years ago

    Clipboard-File-1.png
    Finally solved that issue by this:

    Code
    import dynamic from "next/dynamic"
    Code
    const SurveyComponent = dynamic(() => import("../components/survey"), {   ssr: false, })
      created 4 years ago

      Hello Andrew,
      We are getting this error in import statement while running the NextJS application. Can you please share some workarounds for the same? Any sample code will also help. Thanks in advance!

        Show previous comments (1)

          Hello again,
          We have discussed Next.JS. I learned a little bit about this library.
          So, it is a react server rendering.
          We believe, it doesn't make a lot of sense to render our survey react library on server. You should have a live instance of SurveyJS Model on the client anyway, because surveys contains expressions and logic items. You should get new rendering from server not only on changing current page, but on changing a value of any question. Additionally, the most developers would love to hide the survey generated html from search engines. On of the biggest advantage or SSR is making available your SPA page for search engines. In our case it would be a disadvantage.

          We are going to make SurveyJS Model working on NodeJS. This makes sense.

          Thank you,
          Andrew
          SurveyJS Team

            Clipboard-File-1.png
            this is the issue for next js with survey js
            Clipboard-File-2.png

              Hello,

              This error is in "survey-react-ui" library during rendering. It's not a survey model, it's a UI part. UI parts of SurveyJS control are not support server-side rendering, rendering of SurveyJS components should be performed on a client side in a browser.

              Thanks, Serge
              SurveyJS Team