event-bus icon indicating copy to clipboard operation
event-bus copied to clipboard

No export default

Open templar820 opened this issue 1 year ago • 3 comments

Description

In 2.2.0 all working correctly

Steps to reproduce

import {EventBus} from "@trutoo/event-bus";

const eventBus = new EventBus();

function App() {

  useEffect(() => {
    eventBus.register('namespace:eventName', { type: 'string' });
    const sub = eventBus.subscribe<boolean>('namespace:eventName', ({payload}) => {
      console.log(payload);
    });
    return () => {
      sub.unsubscribe();
    }
  },[])

Error EventBus is not exported. In 2.2.0 all working correctly

Library Version

2.3.0

Browser

  • [X] Chrome
  • [ ] Edge*
  • [ ] Safari
  • [ ] Firefox
  • [ ] Opera
  • [ ] IE
  • [ ] Other

Platform

  • [ ] Windows
  • [ ] MacOS
  • [ ] Linux
  • [ ] Android
  • [ ] iOS
  • [ ] Other

Additional Information

No response

templar820 avatar Jun 06 '24 13:06 templar820

Odd, I'll take a look.

Swiftwork avatar Jun 08 '24 07:06 Swiftwork

@templar820 Thanks for bringing this to our attention. When we upgraded the dependencies rollup CommonJS changed how they handled exports. It no longer includes esModule boolean:

Object.defineProperty(exports, '__esModule', { value: true });

So it is likely that your build system isn't happy with this change. To help us reproduce and resolve this issue could you please provide us with the following information:

  1. Which build tool and version are you using (webpack 5, rollup 4, vite 5, etc...)?
  2. Are you using the named export import { EventBus } from "@trutoo/event-bus"; or are you attempting to use commonjs default require const EventBus = require('@trutoo/event-bus');

We attempted to reproduce your error in a sandbox, but saw no errors https://codesandbox.io/p/sandbox/event-bus-test-92spz4. Try implementing something similar and see if that works.

Until we can resolve your issue feel free to keep using 2.2.0 as very little has changed between the versions other than the build process.

Swiftwork avatar Jun 08 '24 08:06 Swiftwork

Just cra. It's webpack 5. m1 Mac

templar820 avatar Jun 08 '24 11:06 templar820

Latest version v3.0.0 has resolved this issue. The following should work:

import { EventBus } from "@trutoo/event-bus";

Swiftwork avatar Jun 23 '25 09:06 Swiftwork