question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Leaflet: runs fine in dev, but fails in build mode

See original GitHub issue

Environment


  • 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:closed
  • Created a year ago
  • Reactions:1
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
danielroecommented, Sep 26, 2022

I’m closing as there’s no reproduction. Feel free to provide it and I will reopen.

1reaction
daktcommented, Jun 27, 2022

I have the same issue with Nuxt3 and Leaflet : [nuxt] [request error] window is not defined Are you using vue-leaflet or pure js leaflet ?

pure leaflet

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found