Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Issues in combination Sveltekit #573

Open
mindreframer opened this issue May 23, 2023 · 9 comments · May be fixed by #821
Open

[BUG] Issues in combination Sveltekit #573

mindreframer opened this issue May 23, 2023 · 9 comments · May be fixed by #821

Comments

@mindreframer
Copy link

Hey @artalar , thanks for this cool library!

I would like to try it in combination with Svelte. For testing I started using it with sveltekit scaffold and it complaints when I try to render it.

There seems to be an issue with "@reatom/framework" re-exports...

Internal server error: Unexpected token 'export'
      at internalCompileFunction (node:internal/vm:73:18)
      at wrapSafe (node:internal/modules/cjs/loader:1176:20)
      at Module._compile (node:internal/modules/cjs/loader:1218:27)
      at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
      at Module.load (node:internal/modules/cjs/loader:1117:32)
      at Module._load (node:internal/modules/cjs/loader:958:12)
      at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
      at ModuleJob.run (node:internal/modules/esm/module_job:194:25) (x14)
reatom/node_modules/.pnpm/@[email protected]/node_modules/@reatom/framework/build/index.module.js:1
export*from"@reatom/async";export*from"@reatom/core";export*from"@reatom/effects";export*from"@reatom/hooks";export*from"@reatom/lens";export*from"@reatom/logger";export*from"@reatom/primitives";export*from"@reatom/utils";

Repo with reproduction:

Is this a known issue? Some configuration settings to fix it?

Thanks!

@mindreframer
Copy link
Author

In an another, plain Svelte project the importing / bundling works fine...

@mindreframer
Copy link
Author

Example in a sandbox REPL here:

@artalar
Copy link
Owner

artalar commented May 24, 2023

Douno. Did you use the last version of vite, the kit and so on?

@artalar
Copy link
Owner

artalar commented May 24, 2023

Here is the same issue sveltejs/kit#7363

@artalar
Copy link
Owner

artalar commented Jul 7, 2023

@mindreframer try [email protected] plese

@mindreframer
Copy link
Author

Hmm... On NPM I see only 3.1.0...
Screenshot 2023-07-08 at 14 13 36

Also, here is the repo - https://github.com/mindreframer/reatom-sveltekit-issue. Update did not change the error message locally

@nightire
Copy link

nightire commented Mar 20, 2024

I think reatom is currently not compatible with vite@5, because it now only support esm packages.

EDIT: with a bit of digging in, I can confirm the compatible issue and it is relatively easy to fix on reatom side. Just add "type": "module" in package.json of all published packages. cc @artalar

@BANOnotIT
Copy link
Collaborator

@nightire But how "type": "module" can help? All packages already have "exports" with "default" conditions and "module": "./some.js". Can you provide any link on what exactly "type": "module" will change?

@nightire
Copy link

nightire commented Mar 24, 2024

@BANOnotIT I don't know what changed behind the scenes; I just have tried everything to make vite@5 work.

It's easy to try yourself: bootstrap a vite@5 project, install Reatom, and run it to see the error. Then, overwrite the package.json files in the node_modules folder, and everything works well.

EDIT:
Here's my speculation, according to the official document: https://nodejs.org/api/packages.html#type

image

Because of the exports field, modules belonging to Reatom should be fine. However, third-party modules directly dependent on reatom still need the "type": "module" field; otherwise, they will be parsed as CommonJS modules and cause problems with Vite@5.

Again, that's my best guess, but it did works for me.

BANOnotIT added a commit that referenced this issue Apr 20, 2024
fix(async): bundler esm import
fix(core-v1): bundler esm import
fix(core): bundler esm import
fix(effects): bundler esm import
fix(eslint-plugin): bundler esm import
fix(form-web): bundler esm import
fix(form): bundler esm import
fix(framework): bundler esm import
fix(hooks): bundler esm import
fix(jsx): bundler esm import
fix(lens): bundler esm import
fix(logger): bundler esm import
fix(npm-cookie-baker): bundler esm import
fix(npm-history): bundler esm import
fix(npm-lit): bundler esm import
fix(npm-react): bundler esm import
fix(npm-solid-js): bundler esm import
fix(npm-svelte): bundler esm import
fix(npm-vue): bundler esm import
fix(persist-web-storage): bundler esm import
fix(persist): bundler esm import
fix(primitives): bundler esm import
fix(react-v1): bundler esm import
fix(testing): bundler esm import
fix(timer): bundler esm import
fix(undo): bundler esm import
fix(url): bundler esm import
fix(utils): bundler esm import
fix(web-fetch): bundler esm import
fix(web): bundler esm import

Reatom used to use package.json#module field to declare esm modules.
Turns out it was only in draft spec and never was standardized.
So instead of relying on non-standard behaviour we use .mjs which is
standard nodejs mechanizm.

Should fix #816 #806 #573
@BANOnotIT BANOnotIT linked a pull request Apr 20, 2024 that will close this issue
@BANOnotIT BANOnotIT linked a pull request Apr 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants