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

560
Views
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 answers
Answer question

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 Report
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!