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

"Uncaught TypeError: EventEmitter is not a constructor" using vite #441

Closed
fc opened this issue Oct 29, 2021 · 3 comments · Fixed by #451
Closed

"Uncaught TypeError: EventEmitter is not a constructor" using vite #441

fc opened this issue Oct 29, 2021 · 3 comments · Fixed by #451

Comments

@fc
Copy link

fc commented Oct 29, 2021

Steps:

  1. Instantiate mapbox-gl-geocoder

Reproduce it here:
https://replit.com/join/qyvahtyiuq-fc14

Or refer to this code snippet:

import React from 'react';
import MapboxGeocoder from '@mapbox/mapbox-gl-geocoder';
import './App.css';

function App() {
  new MapboxGeocoder({
            accessToken: '',
            mapboxgl: '',
            marker: false,
          });
  return (
    <main>
      React⚛️ + Vite⚡ + Replit🌀
    </main>
  );
}

export default App;

Current:

Uncaught TypeError: EventEmitter is not a constructor
    at new MapboxGeocoder (index.js?b9d5:43)
...

Expected:
No error

Seems like this is because I'm using vite as this worked previously.
events is also not listed as a dependency.

Temporary workaround:
Install events

pnpm install events @types/events
@CyrilAnac
Copy link

Same issue, @fc thanks for the workaround

@janosh
Copy link

janosh commented Jan 2, 2022

So the problem is that mapbox-gl-geocoder needs to specify events as a dep? But then why would it work outside vite?

@mbullington
Copy link
Contributor

Vite doesn't natively do the Node emulation that other bundlers do. See Parcel docs for these examples: https://parceljs.org/features/node-emulation/

This is still our bug—per say. We should include https://www.npmjs.com/package/events in the dependencies.

Thanks!

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

Successfully merging a pull request may close this issue.

4 participants