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

Nextjs ReferenceError: window is not defined #365

Open
andrew-oko-odion opened this issue May 27, 2023 · 2 comments
Open

Nextjs ReferenceError: window is not defined #365

andrew-oko-odion opened this issue May 27, 2023 · 2 comments

Comments

@andrew-oko-odion
Copy link

the code below, causes nextjs to break

const provider = new OpenStreetMapProvider()

Error message

Server Error

ReferenceError: window is not defined
This error happened while generating the page. Any console logs will be displayed in the terminal window.
Call Stack
<unknown>
file:/Users/drew/workspace/js/eventapp/node_modules/leaflet/dist/leaflet-src.js (230:19)
<unknown>
file:/Users/drew/workspace/js/eventapp/node_modules/leaflet/dist/leaflet-src.js (7:66)
Object.<anonymous>
file:/Users/drew/workspace/js/eventapp/node_modules/leaflet/dist/leaflet-src.js (10:3)
Module._compile
node:internal/modules/cjs/loader (1119:14)
Module._extensions..js
node:internal/modules/cjs/loader (1173:10)
Module.load
node:internal/modules/cjs/loader (997:32)
Module._load
node:internal/modules/cjs/loader (838:12)
Module.require
node:internal/modules/cjs/loader (1021:19)
require
node:internal/modules/cjs/helpers (103:18)
Object.<anonymous>
file:/Users/drew/workspace/js/eventapp/node_modules/leaflet-geosearch/dist/geosearch.js (1:292)
Module._compile
node:internal/modules/cjs/loader (1119:14)
Module._extensions..js
node:internal/modules/cjs/loader (1173:10)
Module.load
node:internal/modules/cjs/loader (997:32)
Module._load
node:internal/modules/cjs/loader (838:12)
Module.require
node:internal/modules/cjs/loader (1021:19)
require
node:internal/modules/cjs/helpers (103:18)
leaflet-geosearch
file:/Users/drew/workspace/js/eventapp/.next/server/pages/testui.js (76:18)
__webpack_require__
file:/Users/drew/workspace/js/eventapp/.next/server/webpack-runtime.js (33:42)
eval
webpack-internal:///./pages/testui.js (7:75)
./pages/testui.js
file:/Users/drew/workspace/js/eventapp/.next/server/pages/testui.js (55:1)
__webpack_require__
file:/Users/drew/workspace/js/eventapp/.next/server/webpack-runtime.js (33:42)
__webpack_exec__
file:/Users/drew/workspace/js/eventapp/.next/server/pages/testui.js (119:39)
<unknown>
file:/Users/drew/workspace/js/eventapp/.next/server/pages/testui.js (120:28)
Object.<anonymous>
file:/Users/drew/workspace/js/eventapp/.next/server/pages/testui.js (123:3)
Module._compile
node:internal/modules/cjs/loader (1119:14)
Module._extensions..js
node:internal/modules/cjs/loader (1173:10)
Module.load
node:internal/modules/cjs/loader (997:32)
Module._load
node:internal/modules/cjs/loader (838:12)
Module.require
node:internal/modules/cjs/loader (1021:19)
require
node:internal/modules/cjs/helpers (103:18)
Object.requirePage
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/require.js (134:12)
<unknown>
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/load-components.js (51:73)
process.processTicksAndRejections
node:internal/process/task_queues (95:5)
async Object.loadComponentsImpl [as loadComponents]
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/load-components.js (51:26)
async DevServer.findPageComponentsImpl
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/next-server.js (667:36)
async DevServer.findPageComponents
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/dev/next-dev-server.js (1248:20)
async DevServer.renderPageComponent
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/base-server.js (1187:24)
async DevServer.renderToResponseImpl
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/base-server.js (1230:32)
async DevServer.pipeImpl
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/base-server.js (548:25)
async Object.fn
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/next-server.js (1030:21)
async Router.execute
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/router.js (297:32)
async DevServer.runImpl
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/base-server.js (522:29)
async DevServer.run
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/dev/next-dev-server.js (869:20)
async DevServer.handleRequestImpl
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/base-server.js (456:20)
@cheruiyot-ian-k
Copy link

the code below, causes nextjs to break

const provider = new OpenStreetMapProvider()

Error message

Server Error

ReferenceError: window is not defined
This error happened while generating the page. Any console logs will be displayed in the terminal window.
Call Stack
<unknown>
file:/Users/drew/workspace/js/eventapp/node_modules/leaflet/dist/leaflet-src.js (230:19)
<unknown>
file:/Users/drew/workspace/js/eventapp/node_modules/leaflet/dist/leaflet-src.js (7:66)
Object.<anonymous>
file:/Users/drew/workspace/js/eventapp/node_modules/leaflet/dist/leaflet-src.js (10:3)
Module._compile
node:internal/modules/cjs/loader (1119:14)
Module._extensions..js
node:internal/modules/cjs/loader (1173:10)
Module.load
node:internal/modules/cjs/loader (997:32)
Module._load
node:internal/modules/cjs/loader (838:12)
Module.require
node:internal/modules/cjs/loader (1021:19)
require
node:internal/modules/cjs/helpers (103:18)
Object.<anonymous>
file:/Users/drew/workspace/js/eventapp/node_modules/leaflet-geosearch/dist/geosearch.js (1:292)
Module._compile
node:internal/modules/cjs/loader (1119:14)
Module._extensions..js
node:internal/modules/cjs/loader (1173:10)
Module.load
node:internal/modules/cjs/loader (997:32)
Module._load
node:internal/modules/cjs/loader (838:12)
Module.require
node:internal/modules/cjs/loader (1021:19)
require
node:internal/modules/cjs/helpers (103:18)
leaflet-geosearch
file:/Users/drew/workspace/js/eventapp/.next/server/pages/testui.js (76:18)
__webpack_require__
file:/Users/drew/workspace/js/eventapp/.next/server/webpack-runtime.js (33:42)
eval
webpack-internal:///./pages/testui.js (7:75)
./pages/testui.js
file:/Users/drew/workspace/js/eventapp/.next/server/pages/testui.js (55:1)
__webpack_require__
file:/Users/drew/workspace/js/eventapp/.next/server/webpack-runtime.js (33:42)
__webpack_exec__
file:/Users/drew/workspace/js/eventapp/.next/server/pages/testui.js (119:39)
<unknown>
file:/Users/drew/workspace/js/eventapp/.next/server/pages/testui.js (120:28)
Object.<anonymous>
file:/Users/drew/workspace/js/eventapp/.next/server/pages/testui.js (123:3)
Module._compile
node:internal/modules/cjs/loader (1119:14)
Module._extensions..js
node:internal/modules/cjs/loader (1173:10)
Module.load
node:internal/modules/cjs/loader (997:32)
Module._load
node:internal/modules/cjs/loader (838:12)
Module.require
node:internal/modules/cjs/loader (1021:19)
require
node:internal/modules/cjs/helpers (103:18)
Object.requirePage
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/require.js (134:12)
<unknown>
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/load-components.js (51:73)
process.processTicksAndRejections
node:internal/process/task_queues (95:5)
async Object.loadComponentsImpl [as loadComponents]
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/load-components.js (51:26)
async DevServer.findPageComponentsImpl
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/next-server.js (667:36)
async DevServer.findPageComponents
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/dev/next-dev-server.js (1248:20)
async DevServer.renderPageComponent
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/base-server.js (1187:24)
async DevServer.renderToResponseImpl
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/base-server.js (1230:32)
async DevServer.pipeImpl
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/base-server.js (548:25)
async Object.fn
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/next-server.js (1030:21)
async Router.execute
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/router.js (297:32)
async DevServer.runImpl
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/base-server.js (522:29)
async DevServer.run
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/dev/next-dev-server.js (869:20)
async DevServer.handleRequestImpl
file:/Users/drew/workspace/js/eventapp/node_modules/next/dist/server/base-server.js (456:20)

Were you able to find a workaround?

@chrishoermann
Copy link

I fixed it by importing from

import OpenStreetMapProvider from "leaflet-geosearch/lib/providers/openStreetMapProvider.js";

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

No branches or pull requests

3 participants