Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
require('.') takes top level index.js instead of local one

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 ?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!