Reputation: 2135
I have a React app created with create-react-app. Recently I've added some source code for a module I need. It's in Typescript and will stay in Typescript. Not my choice. I've installed what I needed to build Typescript and that part seems to work OK.
However, when I try importing that TS module to my regular jsx, it says module not found
.
To illustrate:
shared/
- MyTSModule/
- index.tsx
- OtherModule/
- index.jsx
view/
- MyView/
- index.jsx
I'm trying to import MyTSModule
to MyView
. The error is: Module not found: Error: Can't resolve 'shared/MyTSModule' in...
I'm importing like all the other modules from shared
:
import MyTSModule from 'shared/MyTSModule ';
What am I missing?
Upvotes: 2
Views: 2990
Reputation: 374
You cannot import typescript file from javascript. You either need to:
I personally recommend porting all files to typescript, this way you will have more type safety.
Upvotes: 3