Leaflet: runs fine in dev, but fails in build mode
See original GitHub issueEnvironment
- Operating System:
Darwin
- Node Version:
v18.2.0
- Nuxt Version:
3.0.0-rc.3
- Package Manager:
pnpm@7.1.7
- Builder:
vite
- User Config:
-
- Runtime Modules:
-
- Build Modules:
-
Describe the bug
I have UI library which also imports leaflet
dep. I made sure that leaflet
is loaded dynamically in onMounted
hooks and that solved the problem when running in dev mode via vite server, but it fails to run in build mode when using node
command with error log:
[nuxt] [request error] window is not defined
at ./.output/server/chunks/app/server.mjs:17185:21
That line is from leaflet
library, but why does it error out only in production? I also made sure I upgraded node to 18.2.0 which supports ESM, but still fails.
Additional context
No response
Logs
[nuxt] [request error] window is not defined
at ./.output/server/chunks/app/server.mjs:17185:21
at ./.output/server/chunks/app/server.mjs:17058:5
at ./.output/server/chunks/app/server.mjs:17059:5
at ./.output/server/chunks/app/server.mjs:24886:3
at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:409:24)
at async ./.output/server/chunks/handlers/renderer.mjs:11136:24
at async ./.output/server/chunks/handlers/renderer.mjs:11192:64
at async ./.output/server/node_modules/h3/dist/index.mjs:417:19
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:11 (3 by maintainers)
Top Results From Across the Web
React Leaflet works during development, fails on build time ...
Everything works during development, fully functional, but when I try "gatsby build", it fails: Here is the error
Read more >Modern JavaScript · Issue #7615 · Leaflet/Leaflet - GitHub
I think it is time to move to modern JavaScript in the source code. IMPORTANT: This is not a proposal to drop support...
Read more >Mapbox tiles not showing on Leaflet map using Google Chrome
I'm using a Mapbox API access token and the app is hosted from Github. The app works fine from Firefox. enter image description...
Read more >Esri-Leaflet, Geoservices.js, Terraformer, Pushlet
Esri-Leaflet is a Javascript library to help developers build lightweight applications using the Leaflet Javascript mapping library.
Read more >How to solve "window is not defined" errors in React and Next.js
This way your component won't even be rendered on the server-side at all. This solution works particularly well when you're importing external ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m closing as there’s no reproduction. Feel free to provide it and I will reopen.
pure leaflet