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

Reatom doesn't work with esm packages #816

Open
Aetet opened this issue Apr 17, 2024 · 0 comments · May be fixed by #821
Open

Reatom doesn't work with esm packages #816

Aetet opened this issue Apr 17, 2024 · 0 comments · May be fixed by #821
Labels
bug Something isn't working

Comments

@Aetet
Copy link

Aetet commented Apr 17, 2024

What happened?

Bug with esm if we try to import reatom in esm-based package
we got an error:

$ node ./dist/hello.js
file:///check-ts-issue/dist/hello.js:1
import { atom, createCtx } from '@reatom/framework';
         ^^^^
SyntaxError: Named export 'atom' not found. The requested module '@reatom/framework' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@reatom/framework';
const { atom, createCtx } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)

Node.js v18.16.1
error Command failed with exit code 1.

Here's the repo with reproduce:
https://github.com/Aetet/reatom-esm-reproduce

Part

Package @reatom/core

Version

No response

What browsers are you seeing the problem on?

No response

Relevant log output

No response

@Aetet Aetet added the bug Something isn't working label Apr 17, 2024
BANOnotIT added a commit that referenced this issue Apr 20, 2024
Repo is copied from #816 inside to test in future
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant