playcanvas / observer

JavaScript implementation of the Observer pattern
https://api.playcanvas.com/modules/Observer
MIT License
14 stars 5 forks source link

Error `Can't import the named export 'Events' from non EcmaScript module` #4

Closed kungfooman closed 2 months ago

kungfooman commented 2 years ago

From this thread: https://forum.playcanvas.com/t/how-to-add-the-pcui-package-to-a-react-app/22289/4

I tested around with conditional exports in package.json first: https://nodejs.org/api/packages.html#packages_conditional_exports

  "exports": {
    "import": "./index.mjs",
    "require": "./index.js"
  }

But then I realized react-scripts (using webpack) is ignoring that and I just had to remove those two lines to make it work:

https://github.com/playcanvas/playcanvas-observer/blob/6c1ae13c222e8c640252a25979e487c71a57d71f/package.json#L5-L6

Now it works for require and import case, require test via node itself:

image

But I don't know if that breaks other setups, while it works with webpack... everybody is using a different bundler with different import rules and whatnot.

willeastcott commented 2 months ago

I believe this is now fixed. I added publint support to the repo today and it reports no problems. Closing.