mirror of
https://github.com/langgenius/dify-docs-archived.git
synced 2026-07-25 21:46:50 -04:00
web build error [ ReferenceError: window is not defined ] #18
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ssssmy on GitHub (Aug 15, 2024).
➜ web git:(main) ✗ npm run build
yarn run v1.22.22
$ next build
▲ Next.js 14.2.4
Creating an optimized production build ...
✓ Compiled successfully
Skipping validation of types
Skipping linting
✓ Collecting page data
Generating static pages (0/15) [ ]ReferenceError: window is not defined
at /Users/shenmingyuan/docker-data/dify/web/.next/server/chunks/90.js:1:22372
at 53950 (/Users/shenmingyuan/docker-data/dify/web/.next/server/chunks/90.js:1:22780)
at t (/Users/shenmingyuan/docker-data/dify/web/.next/server/webpack-runtime.js:1:143)
at 55378 (/Users/shenmingyuan/docker-data/dify/web/.next/server/chunks/6364.js:122:10331)
at t (/Users/shenmingyuan/docker-data/dify/web/.next/server/webpack-runtime.js:1:143)
at 8894 (/Users/shenmingyuan/docker-data/dify/web/.next/server/app/(commonLayout)/tools/page.js:1:11769)
at Object.t [as require] (/Users/shenmingyuan/docker-data/dify/web/.next/server/webpack-runtime.js:1:143)
at require (/Users/shenmingyuan/docker-data/dify/web/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:16:18365)
at I (/Users/shenmingyuan/docker-data/dify/web/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:94362)
at /Users/shenmingyuan/docker-data/dify/web/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:96668 {
digest: '89040208'
}
Generating static pages (10/15) [= ]
Error occurred prerendering page "/tools". Read more: https://nextjs.org/docs/messages/prerender-error
ReferenceError: window is not defined
at /Users/shenmingyuan/docker-data/dify/web/.next/server/chunks/90.js:1:22372
at 53950 (/Users/shenmingyuan/docker-data/dify/web/.next/server/chunks/90.js:1:22780)
at t (/Users/shenmingyuan/docker-data/dify/web/.next/server/webpack-runtime.js:1:143)
at 55378 (/Users/shenmingyuan/docker-data/dify/web/.next/server/chunks/6364.js:122:10331)
at t (/Users/shenmingyuan/docker-data/dify/web/.next/server/webpack-runtime.js:1:143)
at 8894 (/Users/shenmingyuan/docker-data/dify/web/.next/server/app/(commonLayout)/tools/page.js:1:11769)
at Object.t [as require] (/Users/shenmingyuan/docker-data/dify/web/.next/server/webpack-runtime.js:1:143)
at require (/Users/shenmingyuan/docker-data/dify/web/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:16:18365)
at I (/Users/shenmingyuan/docker-data/dify/web/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:94362)
at /Users/shenmingyuan/docker-data/dify/web/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:96668
✓ Generating static pages (15/15)
@dosubot[bot] commented on GitHub (Aug 15, 2024):
Hey @ssssmy! I'm Dosu, a bot here to help you with bug fixes, questions, and becoming a contributor. Let's squash those bugs together! 🤖
The error
ReferenceError: window is not definedindicates that there is an attempt to access thewindowobject in a server-side context, which is not available. This is a common issue when using browser-specific APIs in server-rendered pages.To resolve this, you should:
Check for Direct References to
window: Ensure that there are no direct references to thewindowobject within the/toolspage or its components .Use Client-Side Only Logic: If you need to use the
windowobject, make sure to wrap the code in a check to ensure it only runs on the client side. For example:Custom Hooks: Verify if any custom hooks used in the
/toolspage are accessing thewindowobject and ensure they are also wrapped in client-side checks .Next.js Configurations: Review any custom Next.js configurations or plugins that might affect the server-side rendering process for the
/toolspage .Environment Variables: Check if there are any specific environment variables or configurations in the
.env.localfile that might affect the rendering behavior of the/toolspage .By addressing these points, you should be able to resolve the
window is not definederror during the build process.To continue talking to Dosu, mention @dosu.
@zhansc commented on GitHub (Aug 26, 2024):
我这边有出现这个问题,通过更新node版本,和dify/web/package.json中指定的版本保持一致,解决了这个问题
原来的node版本:
web % node -v
v22.5.1
重新安装后的版本:
web % node -v
v18.20.4