Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

187
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda