I have a React-Native app that's using a private TypeScript module.
This module, when compiled to JS, add const _1 = require('.'); that's supposed to import the local index.js file inside that same module.
The problem: when the file is imported, it's instead the top level index.js from the root directory of my app that's imported.
I'm pretty sure it's a babel issue since I didn't have this problem before adding the module-resolver plugin into the app.
Here's the content of babel.config.js
module.exports = {
presets: ['module:metro-react-native-babel-preset', '@babel/preset-flow'],
plugins: [
[
'module-resolver',
{
root: ['./'],
alias: {
/**
* Regular expression is used to match all files inside `./src` directory and map each `.src/folder/[..]` to `~src/[..]` path
*/
'^~(.+)': './src/\\1',
},
extensions: ['.ios.js', '.android.js', '.js', '.jsx', '.json', '.tsx', '.ts', '.native.js'],
},
],
'react-native-reanimated/plugin', // Must be last in plugins import order
],
};
All my JS files (except App.js and index.js) are inside the src folder.
I know that a quick fix would be replacing the require('.') with require('./index'), but it will just hide the problem.
Is there anyway to specify that require('.') should take the current index.js instead of the top level one ?