You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using @xstate/svelte and Vitest for my components.
Vitest tries to use the cjs file apparently, instead of the esm one. In that same CJS export, there is a require('svelte/store') and many other requires from svelte.
Svelte however, only exports ESM, which breaks since the require for CJS modules.
SvelteKit seems to target the right file, Vitest on the other hand targets the CJS one.
Here is a screen of the error when running pnpm test:unit
ISSUE:
The import value is wrong in the exports field of the package.json.
The importcurrently links to ./dist/xstate-svelte.cjs.mjs which imports from ./xstate-svelte.cjs.js which is a CJS file.
SOLUTION
I was able to fix the issue by changing the import value to: ./dist/xstate-svelte.esm.js in my node_modules locally, which is the real ESM.
To still comply with CJS, there should be a require entry in the exports file that links to ./dist/xstate-svelte.cjs.js.
ADDITIONAL NOTE
Since Svelte only uses ESM, maybe there is no need for the CJS export here?
Expected result
The import should link to the ESM file rather than the CJS one.
Actual result
The import links to an ESM file that imports from a CJS file.
XState version
XState version 5
Description
Hey there,
I'm using
@xstate/svelte
and Vitest for my components.Vitest tries to use the
cjs
file apparently, instead of the esm one. In that same CJS export, there is arequire('svelte/store')
and many other requires from svelte.Svelte however, only exports ESM, which breaks since the
require
for CJS modules.SvelteKit seems to target the right file, Vitest on the other hand targets the CJS one.
Here is a repo with a reproduction: https://github.com/Shyrro/xstate-svelte-cjs-issue
Here is a screen of the error when running
pnpm test:unit
ISSUE:
The
import
value is wrong in theexports
field of thepackage.json
.The
import
currently links to./dist/xstate-svelte.cjs.mjs
which imports from./xstate-svelte.cjs.js
which is a CJS file.SOLUTION
I was able to fix the issue by changing the
import
value to:./dist/xstate-svelte.esm.js
in mynode_modules
locally, which is the real ESM.To still comply with CJS, there should be a
require
entry in the exports file that links to./dist/xstate-svelte.cjs.js
.ADDITIONAL NOTE
Since Svelte only uses ESM, maybe there is no need for the CJS export here?
Expected result
The
import
should link to the ESM file rather than the CJS one.Actual result
The
import
links to an ESM file that imports from aCJS
file.Reproduction
https://github.com/Shyrro/xstate-svelte-cjs-issue
Additional context
I can open the PR to fix this, just let me know if the solution is okay with you or if there is something i am missing. Thanks.
The text was updated successfully, but these errors were encountered: