Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

186
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda