-
Notifications
You must be signed in to change notification settings - Fork 624
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
Feature: support new package.json exports field #670
Comments
Is there any plan to support this any time soon? |
Any workarounds? |
Here's a workaround I used. In https://github.com/tinyplex/tinybase, I omit the To get this to work with Metro, I added a Works a charm in tinyplex/tinybase#17: |
@robhogan any plans to support this? or we can enable it if it's behind some flag? |
because react native doesn't recognize package.module facebook/metro#670 (comment)
Without this feature it basically makes impossible to use most of ESM modules out there with react-native. |
Hi all 👋, happy to share that |
That's good news. @huntie hopefully this can get bumped up in priority. Lots of popular packages are beginning to drop commonjs support. Without full ESM support in metro react-native users are stuck on increasingly old/broken/insecure versions of packages. |
Hey Folks 👋 |
Update:
Workarounds for apps remain possible by configuring |
Wow thats great, thanks for your answer 🙏 I'm glad to have a workaround. I will try it immediately 🤓 |
We ran into this issue while using fp-ts-std. Our current workaround within a monorepo setup is this: // packages/app/metro.config.js
const path = require('path')
const { createMetroConfiguration } = require('expo-yarn-workspaces')
module.exports = (() => {
const workspaceRoot = path.resolve(__dirname, '../..')
const config = createMetroConfiguration(__dirname)
const { resolver } = config
config.resolver = {
...resolver,
extraNodeModules: new Proxy(resolver.extraNodeModules, {
get: (target, name) => (name === 'fp-ts-std' ? path.resolve(workspaceRoot, `node_modules/${name}/dist/esm`) : undefined)
})
}
return config
})() |
All bundlers will always be behind nodejs itself. Makes me wonder why nodejs can't bundle JS itself. |
Any updates? This is painful for JS library authors. |
Yes I can give an update! 😅 The implementation is well underway — the most recent batch of commits starts with 38b96f8. We're planning to ship Package Exports in the next Metro release, and — fingers crossed — in time for React Native 0.72. For this launch, the feature will be disabled by default and marked "unstable", enabled by the resolver option Furthermore, this will be accompanied by a blog post on the React Native blog. I'll be writing up an explanation of the feature, plus instructions and gotchas for app developers and package maintainers who want to enable the feature today. After this, we're aiming to stabilise Package Exports for React Native 0.73 (pending other priorities). |
Great news, it is in beta now! 😍 https://reactnative.dev/blog/2023/06/21/0.72-metro-package-exports-symlinks#new-metro-features |
exports
field is a new standard which adoption will inevitably grow further as the ecosystem switches to full ESM as NodeJS 10 reaches EOL. It's probably best to support it before things break. Features:Example of subpath exports from NodeJS docs:
The consumer of the library can now use:
The text was updated successfully, but these errors were encountered: