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

Revamp package exports for Metro/React Native #41

Open
kigawas opened this issue Oct 31, 2024 · 2 comments
Open

Revamp package exports for Metro/React Native #41

kigawas opened this issue Oct 31, 2024 · 2 comments

Comments

@kigawas
Copy link
Contributor

kigawas commented Oct 31, 2024

Description

Currently when importing noble-ciphers and noble-hashes on React Native, the following warnings are shown:

 WARN  Attempted to import the module "/Users/user/ReactNativeDemo/node_modules/.pnpm/@[email protected]/node_modules/@noble/ciphers/crypto.js" which is not listed in the "exports" of "/Users/user/ReactNativeDemo/node_modules/.pnpm/@[email protected]/node_modules/@noble/ciphers" under the requested subpath "./crypto.js". Falling back to file-based resolution. Consider updating the call site or asking the package maintainer(s) to expose this API.
 WARN  Attempted to import the module "/Users/user/ReactNativeDemo/node_modules/.pnpm/@[email protected]/node_modules/@noble/hashes/crypto.js" which is not listed in the "exports" of "/Users/user/ReactNativeDemo/node_modules/.pnpm/@[email protected]/node_modules/@noble/hashes" under the requested subpath "./crypto.js". Falling back to file-based resolution. Consider updating the call site or asking the package maintainer(s) to expose this API.

It looks like for metro bundler, import { crypto } from '@noble/ciphers/crypto'; is equivalent to import { crypto } from '@noble/ciphers/crypto.js';. Because "./crypto.js" is not defined in package.json, it falls back to the file-based resolution.

Possible fix

Add "./crypto.js" in package.json can fix the warnings above

    "./crypto.js": {
      "types": "./crypto.d.ts",
      "node": {
        "import": "./esm/cryptoNode.js",
        "default": "./cryptoNode.js"
      },
      "import": "./esm/crypto.js",
      "default": "./crypto.js"
    },

Reference: https://metrobundler.dev/docs/package-exports/

@paulmillr
Copy link
Owner

Can fix or will fix? Test it first.

the imports are there for a reason. It’s the simplest and most compatible way with huge js ecosystem.

We have rollup, webpack, nodejs, and others tested inside of package ethereum-cryptography

@kigawas
Copy link
Contributor Author

kigawas commented Oct 31, 2024

I've tested. It will fix the warning, but it seems kind of redundant

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

No branches or pull requests

2 participants