Cant require 3 times in one file
Hi,
Im using this plugin in a React Native development environtment and im encountering an issue when requiring 3 files in one file. Im requiring 3 .png files like this: require('images/illustration/illustration_x.png)'.
My babel.config.js is set up like this:
module.exports = { presets: ['module:metro-react-native-babel-preset'], plugins: [ [ 'module-resolver', { root: ['./src'] } ] ] }
Requiring two files is no problem, but when the third item is added, im getting the error: 'Cannot resolve file X in node_modules/images/xxxx', meaning the root is no longer in the source folder. This isn't related to one require specific, since commenting them out one by one, always gives the same result.
We are seeing a similar-looking issue when this file is imported:
// Alphabetical order
import * as applicationSources from 'foreground/search/sources/applications';
// WTF
import * as chromeTabSources from './sources/chromeTabs';
import * as contactSources from 'foreground/search/sources/contacts';
import * as docSources from 'foreground/search/sources/docs';
The relative import I have here for chromeTabsSources works, but if I make that path similar to the others, which uses this library, I get:

The file is there...
falcon!ben:/Users/ben/code/tesla$ ls -alh app/foreground/search/sources/chromeTabs.js
-rw-r--r-- 1 ben staff 885B Mar 27 12:02 app/foreground/search/sources/chromeTabs.js
This is the 2nd time I've seen this behavior in 2 weeks. It's very hard to understand what's going on. Both times it was after a file rename and the problem persists after restarting my dev server.
Any ideas?
Usage in babel.config.js
plugins: [
[
require.resolve('babel-plugin-module-resolver'),
{
root: ['./app/'],
alias: {
},
},
],
Version
├─ [email protected]
Babel version
├─ @babel/[email protected]
Weird, so in my case it seems the issue might have been defining alias as an empty object. This seems to work fine...
plugins: [
[
require.resolve('babel-plugin-module-resolver'),
{
root: ['./app/'],
},
],