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

565
Visualizações
I couldn't import from src folder in expo react

I'm using expo-cli.

I import a module from the folder 'src' (i created this folder), if open in web this work perfectly, but if open in android not found this.

I try use the absolute path, the Babel Resolver module and nothing work.

Project:

-assets
-node_modules
-src
  -components
  -screens
    -HomeScreen.js
  -services
    -Webservices.js
  -styles
  -utils
-App.js
...

Screen file:

...

import WebServices from '../services/WebServices';

export default class HomeScreen extends React.Component {

...

File to import:

const axios = require('axios');

var url = 'https://randomuser.me/api/';

var WebServices = {
  getUser: function(){
    return axios.get(url);
  } 
}

export { WebServices as default };

Error:

Android Bundling failed 5347ms
Unable to resolve module ../services/WebServices.js from C:\Users\jalvarez\Proyectos\AppPruebas\src\screens\HomeScreen.js:

None of these files exist:
  * src\services\WebServices.js(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json)
  * src\services\WebServices.js\index(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json)
   5 | import { createNativeStackNavigator } from '@react-navigation/native-stack';
   6 |
>  7 | import WebServices from '../services/WebServices.js';
     |                          ^
   8 |
   9 | export default class HomeScreen extends React.Component {

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Installing Typescript and babel-plugin-root-import modules and with this config in babel.config.js and tsconfig.json work for me in android and web.

balbel.config.js:

module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    plugins: [
      [
       'babel-plugin-root-import',
       {
         root: __dirname,
         rootPathPrefix: '~',
         rootPathSuffix: './src',
       },
      ]
    ]
  };
};

In tsconfig.json add:

"rootDir": "./"

For import:

import WebServices from '~/services/webservices';
about 4 years ago · Juan Pablo Isaza Relatório
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