Open andrew-oko-odion opened 1 year ago
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?
I fixed it by importing from
import OpenStreetMapProvider from "leaflet-geosearch/lib/providers/openStreetMapProvider.js";
the code below, causes nextjs to break
Error message