Zaid-Ajaj / Feliz

A fresh retake of the React API in Fable and a collection of high-quality components to build React applications in F#, optimized for happiness
https://zaid-ajaj.github.io/Feliz/
MIT License
531 stars 77 forks source link

"Directory import use-sync-external-store\shim is not supported" in UseElmish.fs.js #598

Closed reneederer closed 3 months ago

reneederer commented 3 months ago

Hello,

I ran into an exception using mocha.

I created a project using dotnet template "feliz" and added a separate mocha test project. Running mocha dist/fable/Quittiermaske/tests throws the exception:

image

I suspect in fable_modules/Feliz.UseElmish.2.5.0/UseElmish.fs.js the line import { useSyncExternalStore } from "use-sync-external-store/shim"; should actually be import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";. After I changed this line, mocha ran without errors.

reneederer commented 3 months ago

I found a workaround: mocha --loader=ts-node/esm dist/fable/Quittiermaske/tests

MangelMaxime commented 3 months ago

Hello,

The problem is because Mocha does not support ESM out of the box.

Solutions:

  1. Add a loader to mocha like you discovered
  2. Change your tests framework to something like Vitest, Jest, Ava, etc.
  3. Compile your code to CommonJS before executing Mocha