t3-env icon indicating copy to clipboard operation
t3-env copied to clipboard

Only usable in React Native with experimental features due to Package Exports?

Open koengommers opened this issue 1 year ago • 4 comments

This library seems to use Package Exports. Support for Package Exports in Metro is only in beta: https://metrobundler.dev/docs/package-exports/. If the unstable_enablePackageExports is not enabled, an error will occur when attempting to import @t3-oss/env-core, see https://github.com/koengommers/t3-env-expo-issue-repro

Is there some other way to use this library in React Native without having to enable an unstable feature?

koengommers avatar Aug 20 '24 14:08 koengommers

For anyone here still running into this issue after setting unstable_enablePackageExports:

iOS Bundling failed 643ms node_modules/expo-router/entry.js (3235 modules)
The package at "node_modules/axios/dist/node/axios.cjs" attempted to import the Node standard library module "url".
It failed because the native React runtime does not include the Node standard library.
Learn more: https://docs.expo.dev/workflow/using-libraries/#using-third-party-libraries

I've also had to add 'browser' to unstable_conditionNames. Full working metro config:

// Support @t3-oss/env-core
config.resolver.unstable_enablePackageExports = true
config.resolver.unstable_conditionNames = ['browser', ...config.resolver.unstable_conditionNames]

wottpal avatar Dec 04 '24 06:12 wottpal

For anyone here still running into this issue after setting unstable_enablePackageExports:

iOS Bundling failed 643ms node_modules/expo-router/entry.js (3235 modules)
The package at "node_modules/axios/dist/node/axios.cjs" attempted to import the Node standard library module "url".
It failed because the native React runtime does not include the Node standard library.
Learn more: https://docs.expo.dev/workflow/using-libraries/#using-third-party-libraries

I've also had to add 'browser' to unstable_conditionNames. Full working metro config:

// Support @t3-oss/env-core
config.resolver.unstable_enablePackageExports = true
config.resolver.unstable_conditionNames = ['browser', ...config.resolver.unstable_conditionNames]

this should be in the documentation.

carl0smat3us avatar Jun 10 '25 00:06 carl0smat3us

bad idea. I tried to implement this library with these configs. It worked normally until I tried to build the app

the app in production just doesn't work; it always crashes. don't know if this is due to the configs or the library itself

carl0smat3us avatar Jun 21 '25 11:06 carl0smat3us

bad idea. I tried to implement this library with these configs. It worked normally until I tried to build the app

the app in production just doesn't work; it always crashes. don't know if this is due to the configs or the library itself

Hey this is because expo has a way of replacing process.env occurrences as constants during build time, and cant recognize .env :(

dan-myles avatar Oct 11 '25 16:10 dan-myles