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

viem can't be used from CJS modules #34

Closed
alcuadrado opened this issue Feb 1, 2023 · 2 comments
Closed

viem can't be used from CJS modules #34

alcuadrado opened this issue Feb 1, 2023 · 2 comments

Comments

@alcuadrado
Copy link

viem can't be used in a CJS module. I'd say that this is important for its adoption, as it's the default on node.

If you try to do it you get this error:

pato@lucille:v% node -e 'require("viem")'
node:internal/modules/cjs/loader:1269
      throw err;
      ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /private/tmp/v/node_modules/viem/dist/index.js from /private/tmp/v/[eval] not supported.
Instead change the require of index.js in /private/tmp/v/[eval] to a dynamic import() which is available in all CommonJS modules.
    at [eval]:1:1
    at Script.runInThisContext (node:vm:129:12)
    at Object.runInThisContext (node:vm:307:38)
    at [eval]-wrapper:6:22 {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v18.13.0

I think ideally viem should use package.json#exports to support both ESM and CJS.

@alcuadrado
Copy link
Author

Fixed in #37

Copy link
Contributor

github-actions bot commented Jun 3, 2024

This issue has been locked since it has been closed for more than 14 days.

If you found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest Viem version. If you have any questions or comments you can create a new discussion thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant