-
Notifications
You must be signed in to change notification settings - Fork 631
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
metro-file-map: error "Unable to resolve module" while attempting to import a file from outside the project directory #1047
Comments
Hi @retyui - sorry, we should document this better, and the error should be clearer (working on it!).
// in metro.config.js
const config = {
watchFolders: [require('node:path').resolve(__dirname, '..')],
resolver: {
unstable_enableSymlinks: true,
// ...
},
// ...
}; Let us know if that doesn't help. |
@robhogan Now It fail with other error: error: Error: Unable to resolve module @babel/runtime/helpers/interopRequireDefault
from /home/i/all_work/ck/bridging-tutorial/app-info-package/src/index.ts:
@babel/runtime/helpers/interopRequireDefault could not be found within the project. |
We've had a couple of reports of this error. Is there still nothing else in your @huntie - do you have any context here? I recall looking into resolution failures for this package but I don't know whether there were any behaviour changes without |
@robhogan my const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
/**
* Metro configuration
* https://facebook.github.io/metro/docs/configuration
*
* @type {import('metro-config').MetroConfig}
*/
const config = {
watchFolders: [require('node:path').resolve(__dirname, '..')],
resolver: {
unstable_enableSymlinks: true,
},
};
module.exports = mergeConfig(getDefaultConfig(__dirname), config); you can use https://github.com/retyui/demo-metro-bug to investigate this issue |
Ah, this is due to The problem is that that dependency isn't sufficient when transformed code is outside the project root. Metro can't resolve As a workaround, you can add We've already been discussing better approaches to Babel helpers but I hadn't made the connection with workspaces and code sharing, so we might bring that plan forward. Thanks for bringing this up. |
#24561) # Why This is the last remaining issue to build the Android app. # How - Used full dependency chains when resolving packages in Android native files. # Test Plan - `$ pnpm create expo -t tabs@50` - `$ pnpm expo prebuild` - Update all files from this PR - Enable symlinks in **metro.config.js** > `config.resolver.unstable_enableSymlinks = true;` - Manually work around pending Metro issues - Add `@babel/runtime` as project dependency: `$ pnpm add --save-dev @babel/runtime` ([issue](facebook/metro#1047 (comment))) - Add **metro.config.js** settings: ```js config.transformer.asyncRequireModulePath = require.resolve( 'metro-runtime/src/modules/asyncRequire', { paths: [require.resolve('react-native/package.json')] }, ); ``` - `$ pnpm expo run:android` should work > [See this example project](https://github.com/byCedric/expo-50-pnpm) # Checklist <!-- Please check the appropriate items below if they apply to your diff. This is required for changes to Expo modules. --> - [x] Documentation is up to date to reflect these changes (eg: https://docs.expo.dev and README.md). - [ ] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md) - [ ] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin).
@robhogan with regard to this issue with the bable plugin transform, does that mean that a lot of the solutions for doing outside imports discussed in #7 are moot? I've tried everything suggested there to get imports working but all I get is errors talking about the same plugin. I tried the suggestion to add babel runtime as a dependency and it wasn't working on RN: 0.71.7 |
I was fiddling around with importing outside of the root and what I found out that wasn't clear to me before is that if we just want to have a structure like
We don't actually need symlinks per se, and only need to add the shared folder to the watchFolders. But the only caveat here is that everything works except importing a class. IE, if you import functions, constants, etc, that should be fine. but I tried @robhogan suggestion and it works. here's an example barebones 0.72 repo that shows how this works |
For me, I needed to run: |
npx react-native start --reset-cache Solved this by just doing this. |
Or the equivalent if you're using expo: npx expo start --clear |
Do you want to request a feature or report a bug?
bug
What is the current behavior?
My files structure
And when I try to import files outside
SampleApp
metro build is failwith an error
BUT THIS file exist :
Demo Repo: https://github.com/retyui/demo-metro-bug
What is the expected behavior?
the
exists
method indemo-metro-bug/SampleApp/node_modules/metro-file-map/src/lib/TreeFS.js
fileshouldn't return
null
for files outside directoryPlease provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system.
Versions:
metro.config.js
The text was updated successfully, but these errors were encountered: