How to import external typescript files in expo project

Viewed 1163

Is there a way to transpile and support imports from a folder that is outside the expo project's main folder?

I'm looking to just import some additional files from a shared folder.

Here's my setup, and problem:

The root folder

Has 3 subfolders, no package.json, no tsconfig.json, just those:

  • /server --> a nodejs rest api
  • /mobile --> an expo project
  • /shared --> a folder with lots of common typescript files

The mobile folder

This one has the expo project generated with typescript. Project works fine up until I import something from ./shared.

Importing a file from ./shared in the expo folder does not work: (running npm run start in ./mobile fodler)

// mobile/src/screents/login
import { inject } from "../../../../shared/src/core/di"

The error I get is this:

Web:

screenshot with web error

Ios: screenshot with ios error

My assumption is that the file is found yet the babel/typescript transpilation is not triggered. I am uncertain where this aspect can be specified.

My mobile/babel.config.js is the standard one generated by expo:

module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
  };
};

There is no mobile/metro.config.js.

I looked over the docs and got lost in between expo and metro configurations.

1 Answers
Related