event-driven-io / emmett

Emmett - a Node.js library taking your event-driven applications back to the future!
https://event-driven-io.github.io/emmett/
195 stars 19 forks source link

Fix: ESM problem in Nuxt #40

Closed stepaniukm closed 8 months ago

stepaniukm commented 8 months ago

Description

I'm getting the following error when doing import { CommandHandler } from "@event-driven-io/emmett" in a Nuxt project. Somehow Nuxt redirects incorrectly to /dist/index.js instead of /dist/index.mjs.

import { CommandHandler, getInMemoryEventStore } from 'node_modules/@event-driven-io/emmett/dist/index.js';   ^^^^^^^^^^^^^^   SyntaxError: The requested module 'node_modules/@event-driven-io/emmett/dist/index.js' does not provide an export named 'CommandHandler'

Reproduction

Here's the repo with the minimal reproduction: https://stackblitz.com/edit/nuxt-starter-nef6w3?file=app%2Fcounter.ts

Solution to above-mentioned issue

I managed to get rid of that error when I built locally emmet with a field inside package.json

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

But after that I got the following error:

Directory import 'emmett/packages/emmett/dist/commandHandling' is not supported resolving ES modules imported from emmett/packages/emmett/dist/index.mjs
oskardudycz commented 8 months ago

Closed by #39

oskardudycz commented 8 months ago

Read more in How to tackle compatibility issues in ECMA Script modules (and in general).