"window is not defined" error in Next.js 14

Open
#548 8 comments 0 reactions 0 assignees View on GitHub

@brendanbond is already working on this.

Since Jan 24, 2024.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Domain
frontend, web-dev

Research direction

Start by reproducing the Next.js 14 build with the sample in src/app/formioreact/page.tsx and inspect the reported access to window in node_modules/formiojs/providers/storage/s3.js. Compare the listed @formio/react, @formio/js, and formiojs versions. Done means the sample builds without the server-side window error while still rendering the form.

Written by the indexing model from the issue text.

Description

I'm trying to use formio in next js, but I get the following error, but the form seems to render successfully.
Am I using formio correctly? Or does formio not support next js?

Sample Code:

"use client";
import { Form } from "@formio/react";

const Page = () => {
  return (
    <>
      <Form src="https://examples.form.io/example" />
    </>
  );
};

export default Page;

Terminal:

 ⨯ node_modules\formiojs\providers\storage\s3.js (54:22) @ window
 ⨯ ReferenceError: window is not defined
    at __webpack_require__ (C:\Users\user\development\my-app\.next\server\webpack-runtime.js:33:43)
    at __webpack_require__ (C:\Users\user\development\my-app\.next\server\webpack-runtime.js:33:43)
    at __webpack_require__ (C:\Users\user\development\my-app\.next\server\webpack-runtime.js:33:43)
    at __webpack_require__ (C:\Users\user\development\my-app\.next\server\webpack-runtime.js:33:43)
    at __webpack_require__ (C:\Users\user\development\my-app\.next\server\webpack-runtime.js:33:43)
    at __webpack_require__ (C:\Users\user\development\my-app\.next\server\webpack-runtime.js:33:43)
    at __webpack_require__ (C:\Users\user\development\my-app\.next\server\webpack-runtime.js:33:43)
    at __webpack_require__ (C:\Users\user\development\my-app\.next\server\webpack-runtime.js:33:43)
    at __webpack_require__ (C:\Users\user\development\my-app\.next\server\webpack-runtime.js:33:43)
    at __webpack_require__ (C:\Users\user\development\my-app\.next\server\webpack-runtime.js:33:43)
    at eval (./src/app/formioreact/page.tsx:7:71)
    at (ssr)/./src/app/formioreact/page.tsx (C:\Users\user\development\my-app\.next\server\app\formioreact\page.js:228:1)
    at __webpack_require__ (C:\Users\user\development\my-app\.next\server\webpack-runtime.js:33:43)
    at JSON.parse (<anonymous>)
null

package.json

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@formio/js": "^5.0.0-rc.37",
    "@formio/react": "^5.3.0",
    "formiojs": "^4.18.0",
    "next": "14.0.4",
    "react": "^18",
    "react-dom": "^18"
  },
  "devDependencies": {
    "@types/node": "^20",
    "@types/react": "^18",
    "@types/react-dom": "^18",
    "eslint": "^8",
    "eslint-config-next": "14.0.4",
    "typescript": "^5"
  }
}
Dominant language
TypeScript
Stars
371
Forks
309
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from formio/react

All issues in formio/react

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.