E
E
elep52019-11-19 07:43:40
typescript
elep5, 2019-11-19 07:43:40

How to specify default extension to import index.ts in Create React App?

The question is, I import react components through index.js, the import is specified without an extension, that is, I first make a component and then import it into index.js and immediately export it, it works fine with js files, but when switching to ts, if I replace it with index.ts, then import flies because react is looking for a file with a js or json extension.
As I understand it, you need to expand the webpack config and enter there

<code>resolve: {
 extensions: ['.js', '.json', '.ts']</code>

}, but I don't want to EJECT the project. How can I make react see index.ts ?
5dd37218df966672893438.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Didenko, 2019-11-19
@Dasslier

Initiate project with --typescript flag

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question