I've just stumbled upon the fact that I can only import
enums and interfaces from an external TypeScript project into my React Native (with TypeScript) project.
In fact, I think that as long as what I want to import
comes from an export default
module it can work. (So far trying to import
other things like export const
and export function
don't work either.) I feel this is a TypeScript issue and not particular to React Native or Expo frameworks.
What I'm trying to accomplish is as follows:
I've offloaded my entire Redux state tree, actions, and reducers to a separate repository so I can share the code between two frontends (web and react-native). In my React Native and web projects, I've been importing interfaces and enums from a third project all the while, which is my API. Those imports (as I mentioned, so far are only enum
s and interface
s) work just fine.
But when I try to import the store
object, for example, in the web or react native projects, i.e.
import { store } from '../../my-redux-repository/store/index'
It always fails with:
Unable to resolve "../../my-redux-repository/store/index" from "where/im/trying/to/import/it"
Could it be perhaps because the standard store file looks like this in Redux:
export const rootReducer = combineReducers({ foo: fooReducer, bar: barReducer,<<[more reducers here...]>>});export type RootState = ReturnType<typeof rootReducer>;export const store = createStore( rootReducer);
Where there is no default export
but just a variety of export
s?
I tried leveraging Project References from TypeScript. But that doesn't seem to help. I still get the same Unable to resolve...
error.
Does anyone have experience with importing more than just enums and interfaces from an external project? TypeScript's official docs don't go too far into details.
EDIT:
As a sanity check, I've just tried refactoring my store file to:
const store = createStore( rootReducer);export default store;
but this also doesn't work. So the end result is that I'm only able to import default enum
and default interface
items successfully. Otherwise, I'm lost as to what is going wrong.
SECOND EDIT:
It seems that in fact, this is either a React Native or Expo issue, as I can import everything from the redux project just fine (store, action functions, types, etc.) in my Gatsby project (which uses Webpack behind the scenes) - no projects or namespaces required! Just import as expected and it works as expected.