Importing a Custom TypeScript Module from Outside an Expo Project

Please provide the following:

  1. SDK Version: 38
  2. Platforms(all):

I have an external TypeScript Redux module (really its just a repository) which I’d like to share to use in both my native app (Expo) and a web app (Gatsby). Importing the store, actions and others from the module works fine in the Gatsby project, but when I try to import the store in the root of my Expo project, i.e.:

import store from '../../my-redux-project/src/store/index';

I get

Failed building JavaScript bundle.
Unable to resolve "../../my-redux-project/src/store/index" from "src/App.tsx"

I’m using registerRootComponent(App); on my App.tsx file since my App.tsx file sits in /src and not in the root, so not sure if that is causing problems. Currently I do

export default function App() { ....

and at the bottom

registerRootComponent(App);

if I try to do

const App = () => {...

export default registerRootComponent(App);

It doesn’t work at all and expo can’t even connect to it. So I’m not sure if that is the problem

Here is my tsconfig.json for the expo project, it’s a line-for-line copy of the one provided in the typescript integration docs, with the addition of the"resolveJsonModule" option set to true:

{
    "compilerOptions": {
        "allowSyntheticDefaultImports": true,
        "jsx": "react-native",
        "lib": ["dom", "esnext"],
        "moduleResolution": "node",
        "noEmit": true,
        "skipLibCheck": true,
        "resolveJsonModule": true
    }
}

Not sure what the trouble is here. What extra steps am I missing? Surely I don’t have to turn my redux project into an npm module just to use the redux project in my Expo project?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.